简体   繁体   中英

Tab Bar Controller + Navigation Controller + Bar Button Item

Within my MainWindow.xib I have a setup like I have here below. I have a Tab Bar Controller with a Navigation Controller within the Tab Bar Controller. I can switch between the different Navigation Controllers and this all works.

What I am trying to do now is add a Right Bar Button Item to the Navigation Controller. I can't seem to use Interface Builder to drag and drop into the Navigation Controller. Is there a way to add a button to the Navigation Controller... either for specific Views or more preferably that persists throughout all views.

Tab Bar Controller 
    Tab Bar
    Navigation Controller
        Navigation Bar
        XXXXViewController
        Tab Bar Item

You can do it programmatically in viewDidLoad of the controller where you want the right bar button and call the method in its selector depending on what you want that button to do .

UIBarButtonItem *comment = [[UIBarButtonItem alloc]
                            initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
                            target:self
                            action:@selector(displayViewForPosts)];

self.navigationItem.rightBarButtonItem = comment;
[comment release];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM