Storyboard: How to set a UIToolbar at the bottom of a UITableViewController controlled by a UINavigationViewController

StackOverflow https://stackoverflow.com/questions/21686109

문제

I'm new to the Cocoa topic. I build with the Storyboard a small application which runs just fine. I'm pushing UITableViewController to another one, controlled by the UINavigationViewController. Now I need a UIToolbar with a UIBarButtonItem fixed at the bottom of the screen. Here can you see my Storyboard enter image description here So I added via drag and drop a Toolbar and in the toolbar an button into the Period TableViewController, thus it is on the same hierarchic level like the UITableView. Unfortunately neither the "PayOff" Button nor a bottom Toolbar does appear in the app.

Can you help me, what is wrong with my Storyboard?

도움이 되었습니까?

해결책

In your ViewController try adding this

[self.navigationController setToolbarHidden:NO animated:YES];

and use this to add BarItems to it

[self setToolbarItems:@[item1, item2, item3] animated:YES];

I'm using this method to add a scan button to a UITableViewController:

UIBarButtonItem *leftSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *rightSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
...
...
UIBarButtonItem *scanItem = [[UIBarButtonItem alloc] initWithCustomView:scanButton];

[self setToolbarItems:@[leftSpace, scanItem, rightSpace] animated:YES];

You should be careful because the ToolBar visibility is set for the entire NavigationController you are using and you should show/hide it when needed.

Also the items on it need to be set on each controller (I have this issue, maybe there is a better way to do it)

Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top