我试图列出许多 UISegmentControls 的选定索引。我分别在1、2、3、4、5上设置了5个,使用这段代码后的结果(在数组中)是:2、2、0、0、0...
for (UISegmentedControl *seg in segmentArray)
{
NSString* xWrapped = [NSString stringWithFormat:@"%d", seg.selectedSegmentIndex+1];
[difficultyH addObject: xWrapped];
}
为什么??
编辑:
这是创建细分的方式:
//segment controll
NSArray *itemArray2 = [NSArray arrayWithObjects: @"very easy", @"easy", @"ok", @"hard", @"challenging", nil];
UISegmentedControl *segmentedControl2 = [[UISegmentedControl alloc] initWithItems:itemArray2];
segmentedControl2.frame = CGRectMake(480, -60, 130, 350);
segmentedControl2.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl2.selectedSegmentIndex = val - 1;
[segmentedControl2 addTarget:self action:@selector(segmentedControlHomework:) forControlEvents:UIControlEventValueChanged];
segmentedControl2.transform =
CGAffineTransformRotate(segmentedControl2.transform, degreesToRadians(90));
NSArray *arr = [segmentedControl2 subviews];
for (int i = 0; i < [arr count]; i++) {
UIView *v = (UIView*) [arr objectAtIndex:i];
NSArray *subarr = [v subviews];
for (int j = 0; j < [subarr count]; j++) {
if ([[subarr objectAtIndex:j] isKindOfClass:[UILabel class]]) {
UILabel *l = (UILabel*) [subarr objectAtIndex:j];
l.transform = CGAffineTransformMakeRotation(- M_PI / 2.0); //do the reverse of what Ben did
}
}
}
[image1 addSubview:segmentedControl2];
segmentedControl2.tag = i;
[segmentArray addObject: segmentedControl2];
//segment controll