選擇段我在一個UITableView一個headerview一個UISegmentedControl。出於某種原因,我無法選擇任何分段,只要我這樣做,它會自動選擇數組中的最後一個分段,而我不能選擇其他任何分段。當我刪除該動作時,我可以選擇哪一個。不知道發生了什麼事。的iOS不能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;
}
你在說什麼?我沒有對這種性質說過什麼? –
哦,對不起。我想寫這個到另一個問題。 – 2012-12-21 18:36:07
@JonErickson,創建'控制= [[UISegmentedControl alloc] initWithItems:itemArray];'在viewDidLoad左右,並再次檢查。還要移動'[control addTarget:self action:@selector(unitSegmentControl :) forControlEvents:UIControlEventValueChanged];'viewDidLoad。 – iDev