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_btnます。で割り当てを開始しviewDidLoadます

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 に答える