我正在以编程方式将 UISegmentedControl 添加到分组 UITableView 的脚下。它显示得很好,但是当我点击任何选项时,它们都不会突出显示。我在这里做错了什么?另外,如何设置要突出显示的默认项目?
- (void)viewDidLoad
{
[super viewDidLoad];
// set up cacheControl
NSArray* cacheDays = [NSArray arrayWithObjects: @"1", @"2", @"3", @"4", @"5", nil];
self.cacheControl = [[UISegmentedControl alloc] initWithItems:cacheDays];
[self.cacheControl setTintColor:[UIColor blackColor]];
[self.cacheControl addTarget:self action:@selector(cacheSelection:) forControlEvents:UIControlEventValueChanged];
self.cacheControl.frame = CGRectMake(10, 16, self.tbl.frame.size.width-20, 47);
[self.cacheControl setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
}
- (UIView *)tableView:(UITableView *)tv viewForFooterInSection:(NSInteger)section
{
switch (section) {
case 0:{
UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tbl.frame.size.width, tbl.contentInset.top)];
footerView.backgroundColor = [UIColor clearColor];
return footerView;
}
case 1:{
UIView* footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tbl.frame.size.width, 16)];
footerView.backgroundColor = [UIColor clearColor];
[footerView setClipsToBounds:NO];
[footerView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin];
[footerView addSubview:self.cacheControl];
return footerView;
}
}
return nil;
}
截图,按要求: