我有一个UIViewController,我在InterfaceBuilder中添加了一个navigationItem来查看标题,我发现我无法将backBarButtonItem拖到navigationItem,只能添加leftBarButtonItem和rightBarButtonItem。所以我尝试在我的控制器代码中将 backBarButtonItem 添加到 navigationItem 元素:
- (void)viewWillAppear:(BOOL)animated {
UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
self.myNavigationItem.backBarButtonItem = _backButton;
[_backButton release];
}
但是视图上仍然没有 backBarButtonItem?如何解决?