我创建了一个自定义右视图,如下所示:
// Build the Segmented Control
NSArray *segmentTextContent = [NSArray arrayWithObjects:[UIImage imageNamed:@"arrow-dice.png"], [UIImage imageNamed:@"arrow-up.png"], [UIImage imageNamed:@"arrow-down.png"], nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
// Customize the Segmented Control
segmentedControl.momentary = YES;
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
[segmentedControl addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
然后我将其添加到导航栏,如下所示:
// Add the control to the navigation bar right item
UIBarButtonItem *segmentItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentItem;
self.navigationItem.rightBarButtonItem.title = @"";
[segmentItem release];
我可以隐藏它如下:
self.navigationItem.rightBarButtonItem.customView.hidden = NO;
问 ...但是如何禁用分段控件的所有(或更好的,特定元素)?
以下不起作用。
self.navigationItem.rightBarButtonItem.enabled = NO;
任何想法都赞赏......
谢谢,
亚光
答案 0 :(得分:5)
UISegmentedControl.h
- (void)removeSegmentAtIndex:(NSUInteger)segment animated:(BOOL)animated;
- (void)removeAllSegments;
- (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)segment; //default is YES
e.g. [segmentedControl setEnabled:NO forSegmentAtIndex:1];
希望有所帮助
答案 1 :(得分:0)
[navItem.rightBarButtonItem setEnabled:NO];
就这么简单:)
参考:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIBarItem_Class/Reference/Reference.html 请参阅已启用属性。