我正在尝试禁用我添加到导航控制器栏的按钮。这是我添加它的方式:
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStylePlain target:self action:@selector(addNew)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
启用/禁用这些项目的最佳方法是什么?我试过这段代码:
addButton.disabled = YES;
但它当然不起作用。任何帮助,将不胜感激。感谢。
编辑:应该是addButton.enabled = YES;
糟糕
答案 0 :(得分:1)
如果您在标题中定义了addButton
,并且@synthesize它,那么您将能够使用addButton.enabled = NO;
,没有“禁用”设置器。
@interface MyViewController {
UIBarButtonItem *addButton;
}
@property(nonatomic,retain) UIBarButtonItem *addButton;
@end
@implementation MyViewController
@synthesize addButton;
-(void)viewDidLoad{
addButton = [[UIBarButtonItem alloc] initWithTitle:@"Add" style:UIBarButtonItemStylePlain target:self action:@selector(addNew)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
}
-(void)DoSomething{
addButton.enabled = NO;
}