我在 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;
}