私は、2 つのバー ボタンを含むナビゲーション アイテムを含むナビゲーション バーを持っています。これらはストーリーボードで作成され、実行時にボタンの 1 つを変更したかったのですが、これで動作します。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UINavigationItem *thisNavBar = [self myNavigationItem];
thisNavBar.rightBarButtonItem = nil; // this works, it gets removed
UIBarButtonItem *insertBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(insertSkemaItem:)];
thisNavBar.rightBarButtonItem = insertBtn; // this also works, it sets the btn
}
今、別のコントローラーによって呼び出される私の他のメソッドでは、機能しません
- (void)callChildChange {
...
// remove old btn
UINavigationItem *thisNavBar = [self skemaNavigationItem];
thisNavBar.rightBarButtonItem = nil; // does not work?
}
メソッドに問題はありません。正常に実行されますが、nav btn アイテムは削除されませんか?
skemaNavigationItem は、ストーリーボードを介して作成したナビゲーション アイテムをリンクする .h ファイルで宣言されたナビゲーション アイテムです。