我的 UINavigationController 右侧有两个按预期工作的按钮。这是我用来实现这一点的代码:
// Share Button
UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
[shareButton setFrame:CGRectMake(0,0,19,21)];
[shareButton addTarget:self action:@selector(shareButton) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *shareBarButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(shareButton)] autorelease];
shareBarButton.tintColor = [UIColor whiteColor];
// Snapback Button
UIButton *navSnapbackButton = [UIButton buttonWithType:UIButtonTypeCustom];
[navSnapbackButton setFrame:CGRectMake(0,0,26,21)];
[navSnapbackButton setImage:[UIImage imageNamed:@"Snapback.png"] forState:UIControlStateNormal];
[navSnapbackButton addTarget:self action:@selector(snapbackButton) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *navSnapbackBarButton = [[[UIBarButtonItem alloc] initWithCustomView:navSnapbackButton] autorelease];
navSnapbackButton.tintColor = [UIColor whiteColor];
// Right Toolbar Button Setup
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:navSnapbackBarButton, shareBarButton, nil]];
我有一个简单的要求:如何禁用此数组中的按钮?例如说在特定条件下我希望禁用共享按钮,我将如何执行此操作?提前致谢!