gpt4 book ai didi

iphone - 禁用 UINavigationItem 自定义右 View ?

转载 作者:行者123 更新时间:2023-12-03 16:27:58 30 4
gpt4 key购买 nike

我创建了一个自定义右 View ,如下所示:

// 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;

任何想法表示赞赏...

谢谢,
哑光

最佳答案

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];

希望有帮助

关于iphone - 禁用 UINavigationItem 自定义右 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/875025/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com