Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable a UISegmentedControl?

I have the following UISegmentedControl, which I want to be disabled:

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

I don't have it enabled anywhere in the code. Yet I can still click on it, and it will perform the action in titleBarButtonChanged:

How can I make sure it can't be clicked?

like image 658
Sheehan Alam Avatar asked Nov 07 '11 18:11

Sheehan Alam


2 Answers

Try using:

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

or

titleSegmentedControl.userInteractionEnabled = NO;
like image 99
jamapag Avatar answered Oct 07 '22 15:10

jamapag


Within titleBarButtonChanged:(id)sender add:

if(!sender.enabled) return;
like image 31
Tim Avatar answered Oct 07 '22 15:10

Tim