UISegmentControl configuration
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 75, 25)];
label.textAlignment = UITextAlignmentRight;
label.tag = kLabelTag;
label.font = [UIFont boldSystemFontOfSize:14];
label.text = @"Lawn Sign";
[cell.contentView addSubview:label];
[label release];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
NSArray * item = [ NSArray arrayWithObjects:@"No",@"Install",@"Replace",@"Move", nil];
[segmentedControl initWithItems:item];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(90, 10, 200, 30);
[segmentedControl setMomentary:YES];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEven开发者_运维问答ts:UIControlEventValueChanged];
segmentedControl.tag = 14;
[cell.contentView addSubview:segmentedControl];
[segmentedControl release];
Here's my UISegmentedControl
configuration for a cell in the tableview but when I tap on an option in the segmentedControl
, it doesn't switch.
You've set the control to be momentary. Change this:
[segmentedControl setMomentary:YES];
to this:
[segmentedControl setMomentary:NO];
and the control will show its selected state.
精彩评论