我有以下要禁用的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;

10-04 19:48