rightbarbuttonitemをuiviewcontrollerに追加することはできません
-
26-10-2019 - |
質問
次のコードがあります:
- (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;
助言がありますか ?
ありがとうございました
解決 2
遅れて申し訳ありませんが、それを機能させるには、メソッドをviewdapearに適用する必要があります
他のヒント
ivarを排除します update_btn
. 。割り当てを開始します viewDidLoad
と
UIBarButtonItem *update_btn = [[UIBarButtonItem alloc] init...;
このステートメントでアイテムを割り当てます。
self.navigationItem.rightBarButtonItem = update_btn;
[update_btn release];
これがあなたのためにうまくいくかどうか教えてください。
所属していません StackOverflow