【发布时间】:2012-12-21 18:18:12
【问题描述】:
我在 UITableView 的 headerview 中有一个 UISegmentedControl。由于某种原因,我无法选择任何段,每当我这样做时,它都会自动选择数组中的最后一个段,而我无法选择其他任何段。当我删除动作时,我可以选择哪个。不知道发生了什么。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (section == 1) {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 40)]; // x,y,width,height
NSArray *itemArray = [NSArray arrayWithObjects:@"E01", @"E02", @"E03", @"E05", @"E06", @"T05", @"E17", @"E19", nil];
control = [[UISegmentedControl alloc] initWithItems:itemArray];
[control setFrame:CGRectMake(30.0, 0, (tableView.bounds.size.width) - 60, 40)];
[control setSelected:YES];
[control setSegmentedControlStyle:UISegmentedControlStylePlain];
[control addTarget:self action:@selector(unitSegmentControl:) forControlEvents:UIControlEventValueChanged];
[headerView addSubview:control];
return headerView;
}
return nil;
}
【问题讨论】:
-
你在说什么?我没有对那种性质说什么?
-
哦,对不起。我想把它写到另一个问题。
-
@JonErickson,在 viewDidLoad 左右创建
control = [[UISegmentedControl alloc] initWithItems:itemArray];并再次检查。同时将[control addTarget:self action:@selector(unitSegmentControl:) forControlEvents:UIControlEventValueChanged];移动到viewDidLoad。
标签: ios arrays header tableview uisegmentedcontrol