2

我有下一个代码:

- (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"];
}

但是 rightBarButton 是不可见的。

我尝试将代码移动到 viewDidLoad,并将按钮设置为 navigationController.navigationItem 但不显示按钮

self.navigationController.navigationItem.rightBarButtonItem = update_btn;

有什么建议么 ?

谢谢

4

2 回答 2

1

消除 ivar update_btnviewDidLoad开始您的分配

UIBarButtonItem *update_btn = [[UIBarButtonItem alloc] init...;

使用以下语句分配项目:

self.navigationItem.rightBarButtonItem = update_btn;
[update_btn release];

让我知道这是否适合您。

于 2011-09-05T18:05:43.873 回答
0

抱歉耽搁了,要使其正常工作,您必须在方法 viewDidAppear 中应用 UIBarButtonItem

于 2015-01-30T10:44:11.743 回答