Add UIBarButtonItem in interface builder, how to?
I have a navigation based application that have a uinavigataioncontroller containing uitableviewcontrollers. I want to add buttons to the UINavigationbar of the uinavigataioncontroller, usually I write code to add these buttons, something like this:
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveClicked:)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];
My idea now was to use interface builder instead. But I'm not sure how to do it. What I'm trying to do is to add a UINavigationItem in the xib file of the viewc开发者_Go百科ontroller (my viewcontroller is called TextViewController), something like this:
See this image: http://i48.tinypic.com/qq5yk7.jpg
But how can I make TextViewController use the UINavigationItem I added? The button I add doesn't show in the navigationbar.
Any ideas on how to do this? What am I missing?
You can.
All you have to do is drag UIBarButtonItem from Object Library to corresponding NavigationBar of your Xib.
After that then you can connect it to become an IBOutlet of your class.
You can take a bar button in the coding like IBOutlet UIBarButtonItem * saveButton;
Then you have to take a bar button in the xib file and bind this button with that and in coding you can directly write self.navigationItem.rightBarButtonItem = saveButton;
Its almost the same as your code but the only thing changes is you dont have to initialize the barbutton..
Happy coding...
精彩评论