iPhone: Is it possible to have an 'info'-b

2019-06-01 10:36发布

As mentioned in the title, how do I implement such a functionality?

I am using the code below, (in my viewDidLoad), to get the button on my Navigation Controller of my main view.

UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];

[infoButton addTarget:self action:@selector(viewWillAppear:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];

Not sure how I can get it displayed in all my views.

3条回答
该账号已被封号
2楼-- · 2019-06-01 10:58

I would suggest you create an base view controller, and add the bar button to your navigationItem in viewDidLoad. Then all your view controllers subclass from the base controller, rather than the default UIViewController. This should solve your problem.

查看更多
聊天终结者
3楼-- · 2019-06-01 11:09

Each view pushed to the navigation stack has an own navigation bar. So I afraid you have to add this button to each navigation bar, when you create a view and before you push this view to the navigation stack.

查看更多
ら.Afraid
4楼-- · 2019-06-01 11:09

You could simply add an info button to the window, instead of creating a new button for each view controller. Since the window never changes, the button will always be on screen. You only have to take care that no other views are on top of the button.

查看更多
登录 后发表回答