我有下一个代码:
- (id) initWith...{
if (self == [super initWithNibName:@"EmptyViewController"
bundle:[NSBundle mainBundle]]){
...
back_btn = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(backParentViewController)];
self.navigationItem.leftBarButtonItem = back_btn;
update_btn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
target:self action:@selector(refresh)];
self.navigationItem.rightBarButtonItem = update_btn;
self.title = [utils LabelFromKey:@"commons.nav-button.reports"];
self.navigationItem.title = [utils LabelFromKey:@"commons.nav-button.reports"];
}
但右边的BarButton不可见。
我尝试将代码移动到viewDidLoad,并将按钮设置为navigationController.navigationItem但不显示按钮
self.navigationController.navigationItem.rightBarButtonItem = update_btn;
任何建议¿?
谢谢
答案 0 :(得分:0)
消灭ivar update_btn
。使用
viewDidLoad
开始分配
UIBarButtonItem *update_btn = [[UIBarButtonItem alloc] init...;
使用以下声明分配项目:
self.navigationItem.rightBarButtonItem = update_btn;
[update_btn release];
请告诉我这是否适合您。
答案 1 :(得分:0)
很抱歉延迟,为了使它有效,你必须在方法viewDidAppear中应用UIBarButtonItem