Following is the code for UISegmentedControl
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects: [UIImage imageNamed:@"down.png"], [UIImage imageNamed:@"dList.png"], nil]];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
segmentedControl.frame = CGRectMake(0, 0, 90, 65);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.momentary = YES;
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:segmentedControl];
[segmentedControl release];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[segmentBarItem release];
and
- (void)segmentAction:(id)sender{
if([sender selectedSegmentIndex] == 0)
{
button.hidden=NO;
}
else
{
[self dListMethod ];
}
}
In the if() section I want to disable selectedSegmentIndex==0
and enable when button.hidden=YES
Use setEnabled:forSegmentAtIndex:
method to enable and disable the segments.
[segmentedControl setEnabled:NO forSegmentAtIndex:0];
if you want to disable the first segment.