6

私は無効にすることにしたい、次の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でアクションを実行します:

どうしてクリックできないのですか?

答えて

18

は、使用してみてください:

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

または

titleSegmentedControl.userInteractionEnabled = NO; 
+0

個々のセグメントの作品を無効にします。 – DataGraham

3

titleBarButtonChanged:(id)senderアドオンの中で:

if(!sender.enabled) return; 
関連する問題