UINavigationController Toolbar Buttons

I have a UINavigationController that I set as the rootViewController of my window. In the NIB file, I configured it so that it has a “Bottom Panel” in the “Toolbar”. In Interface Builder, I added UIBarButtonItem. All of this works great, and I can handle the click of a button. When I click one of the buttons, I click a new view on the ViewController, and it works fine. One of the problems my button disappears when loading a view. Now in the next view, I can set the bottom panel as a toolbar, and I see it in Interface Builder, but I can not add any buttons to it.

I know that I either missed something obvious or thought about it wrong, but how to add UIBarButtonItems to subsequent views that were ported to my nav controller? I speak in the bar below, but not in the navigation bar at the top.

Any ideas?

+4
source share
2 answers

The toolbarItems property in the UIViewController is what interests you. You can programmatically create UIBarButtonItems and add them to the new toolBarItems array in viewDidLoad.

- (void)viewDidLoad { [super viewDidLoad]; UIBarButtonItem* editButton = [[[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(editAction)] autorelease]; [self setToolbarItems:[NSArray arrayWithObject:editButton]]; } 
+11
source

This helped me better:

 [[self navigationItem] setLeftBarButtonItem:homeButton]; 

You can do the same for the right side.

-2
source

Source: https://habr.com/ru/post/1343715/


All Articles