开发者

How to add a bar button item in interface builder?

开发者 https://www.devze.com 2023-02-17 14:08 出处:网络
I am really new to iPhone development and I need help setting up my views. I have a view that is named FirstViewController.xib and a controller class for this view.

I am really new to iPhone development and I need help setting up my views.

I have a view that is named FirstViewController.xib and a controller class for this view.

In my MainWindox.xib I have setup a root controller with a moveToNextView function that is connected to the opti开发者_C百科ons bar button item.

So when I click on this item the current view switches to the first view and I am able to swticht back. That works fine so far.

The navigation bar at the top of the screen from the MainWindow.xib is displayed in the first view, too. But when I open FirstViewController.xib there isn't any navigation bar defined (but on build&run it is displayed).

This is a problem for me because I want to add a save bar item to the first view. How do I solve that?


Assuming you have a UIViewController (or UIViewController subclass) that is a child of a UINavigationController. Note, I'm using storyboards so your results may vary when using xibs.

  • If you do not see a UINavigationBar on the interface, try manually changing the simulated metrics.

  • Drag a Navigation Item onto the view (anywhere). You should now have a place to enter the title in the interface builder.

How to add a bar button item in interface builder?

  • Now you can drag Bar Button Items onto the nav bar.

How to add a bar button item in interface builder?


You have to do it from code. Add to your FirstViewController class viewDidLoad method:

  UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStyleDone target:self action:@selector(doSave:)];
  self.navigationItem.rightBarButtonItem = anotherButton;
  [anotherButton release];


Just drag a bar button item onto your nav bar in Interface Builder. Xcode automatically wires it up then you can use it like anything else...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号