iPhone: Is it possible to have an 'info'-button in all views in my app?
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:UIControlEventTouchUp开发者_运维问答Inside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];
Not sure how I can get it displayed in all my views.
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.
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.
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.
精彩评论