经历了针对这个问题的每一个stackoverflow解决方案之后,它仍然令人沮丧地不适合我.
//UIBarButtonItem declaration UIBarButtonItem* button1 = [[UIBarButtonItem alloc] initWithTitle:@"Button Text" style:UIBarButtonItemStyleBordered target:self action:@selector(myAction)]; //method 1 [self setToolbarItems:[NSArray arrayWithObjects: button1,nil] animated:YES]; //method 2 [self.navigationController.toolbar setItems:[NSArray arrayWithObject:button1]]; //method 3 self.navigationController.toolbarItems = [NSArray arrayWithObject:button1]; //displaying toolbar [self.navigationController setToolbarHidden:NO];
解决方法
移动
//UIBarButtonItem declaration UIBarButtonItem* button1 = [[UIBarButtonItem alloc] initWithTitle:@"Button Text" style:UIBarButtonItemStyleBordered target:self action:@selector(myAction)]; //method 1 [self setToolbarItems:[NSArray arrayWithObjects: button1,nil] animated:YES]; //displaying toolbar [self.navigationController setToolbarHidden:NO];
to viewDidAppear:(BOOL)animated这是UINavigationController获取它管理的UIViewController工具栏项的点.