有谁知道如何隐藏 arightBarButtonItem
的 a UINavigationController
?rightBarButtonItem
在我的应用程序中,我有一个编辑按钮作为UINavigationController
. 我想隐藏这个?完成某些操作时的 UIBarButton`。
3 回答
To Hide the right button: self.navigationItem.rightBarButtonItem = nil;
Now, to show it:
If you setup the right button in your view controller by assigning it to self.editButtonItem then simply assign it again in order to show it:
self.navigationItem.rightBarButtonItem = self.editButtonItem;
If you setup the right button in your view controller by allocating and initing a UIBarButtonItem, then simply keep a reference to the UIBarButtonItem in your view controller, and assign it again when you need to show it.
尝试
self.navigationItem.rightBarButtonItem = nil;
当你想要它回来时,你将不得不实例化一个按钮,即
UIBarButtonItem *rightBarButton =
[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
target:self
action:@selector(searchBar:)];
self.navigationItem.rightBarButtonItem = rightBarButton;
[rightBarButton release];
如果您需要根据某些条件隐藏/显示按钮,请尝试以下操作:
if (condition) {
self.navigationItem.rightBarButtonItem.title = @"";
self.navigationItem.rightBarButtonItem.enabled = NO;
} else {
self.navigationItem.rightBarButtonItem.title = @"my button title";
self.navigationItem.rightBarButtonItem.enabled = YES;
}
这样您就不必在属性中保存对按钮的引用,也不必担心在新按钮上连接操作。