UIToolbar не показывает UIBarButtonItem
Я использую раскадровку, и у меня есть разделенное представление, где мастер - это UITableViewController. Как приложение iPad Mail, я хотел бы отобразить UIToolbar.
Мне не удалось добавить панель инструментов через раскадровку, но мне удалось добавить ее программно. Я также могу добавить UILabel на панель инструментов, но я не могу найти способ добавить кнопку обновления или любой тип UIBarButtonItem.
Любая идея?
- (void)viewDidLoad {
[super viewDidLoad];
[self.navigationController setToolbarHidden:NO];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50.0f, 0.0f, 80.0f, 40.0f)];
label.text = @"last updated...";
label.textAlignment = UITextAlignmentCenter;
label.font = [UIFont systemFontOfSize:13.0];
[self.navigationController.toolbar addSubview:label];
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStylePlain target:self action:@selector(action:)];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"Item1" style:UIBarButtonItemStyleBordered target:self action:@selector(action:)];
NSArray *buttons = @[item1, item2, nil];
[self.navigationController.toolbar setItems:buttons animated:NO];
Ответы
Ответ 1
Найден ответ благодаря форуму Apple iOS!
Когда вы используете панель инструментов контроллера навигации, вы должны установить кнопки панели инструментов в свойстве toolbarItems на контроллерах представлений, а не на самой панели инструментов.
например:
[self setToolbarItems:buttons animated:NO];