Я добавляю UISegmentedControl под ногу сгруппированного UITableView программно. Он отображается хорошо, но когда я нажимаю на любой из вариантов, они не выделяются. Что я здесь делаю неправильно? Кроме того, как установить выделенный элемент по умолчанию?UISegmentedControl не отвечает
- (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;
}
Скриншот, в соответствии с просьбой:
Не могли бы вы разместить снимок экрана? – Undo
Несомненно. Просто отредактирован. – hodgesmr
Этот ответ из аналогичного вопроса исправил его для меня: http://stackoverflow.com/a/12436632/107821 – hodgesmr