6

Ho il seguente UISegmentedControl, che voglio essere disabilitato:Come disabilitare un 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]; 
} 

io non ce l'ho attivato in qualsiasi parte del codice. Tuttavia, posso ancora fare clic su di esso ed eseguirà l'azione in titleBarButtonChanged:

Come posso essere sicuro che non possa essere cliccato?

risposta

18

Provare a utilizzare:

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

o

titleSegmentedControl.userInteractionEnabled = NO; 
+0

Disattivazione singoli segmenti funziona. – DataGraham

3

Entro titleBarButtonChanged:(id)sender aggiuntivo:

if(!sender.enabled) return; 
Problemi correlati