iphone - 如何禁用 UISegmentedControl?

标签 iphone objective-c cocoa-touch uibarbuttonitem uisegmentedcontrol

我有以下 UISegmentedControl,我想禁用它:

-(void)displayCheckMark
{
    titleSegmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
    [titleSegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"symbolbg.png"] atIndex:0 animated:YES];
    [titleSegmentedControl insertSegmentWithImage:[UIImage imageNamed:@"inwatchlist.png"] atIndex:1 animated:YES];
    [titleSegmentedControl addTarget:self action:@selector(titleBarButtonChanged:)forControlEvents:UIControlEventValueChanged];
    titleSegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
    titleSegmentedControl.frame = CGRectMake(100,0,100,30);
    titleSegmentedControl.momentary = YES;
    titleSegmentedControl.tintColor = [UIColor blackColor];
    self.navigationItem.titleView = titleSegmentedControl;

    [titleSegmentedControl setWidth:60 forSegmentAtIndex:0];
    [titleSegmentedControl setTitle:symbol forSegmentAtIndex:0];
    [titleSegmentedControl setWidth:30 forSegmentAtIndex:1];
    [titleSegmentedControl setEnabled:NO];
}

我没有在代码的任何地方启用它。但是我仍然可以点击它,它会执行 titleBarButtonChanged 中的操作:

如何确保它不能被点击?

最佳答案

尝试使用:

- (void)setEnabled:(BOOL)enabled forSegmentAtIndex:(NSUInteger)segment;

titleSegmentedControl.userInteractionEnabled = NO;

关于iphone - 如何禁用 UISegmentedControl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8041076/

相关文章:

ios - 升级到 iOS9 后登录流程失败

ios - 为什么我的图像在运行 iOS 6 的 iPod 上以纵向模式拍摄时被设置为 UIImageOrientationRight?

iOS 系统在打开 App Store URL 之前挂起

objective-c - 从对象的 NSArray 中提取属性

ios - MKMapView如何知道旋转角度?

iphone - 本地化:在模拟器中更改语言时应用程序崩溃

iphone - Corebluetooth 连接如何在连接时节省电池电量

iphone - 我可以观看另一个类(class)的 NSNotification 吗?

ios - UITableView 委托(delegate)未被调用

ios - 从 1970 年创建带有字符串时间的 NSDate