Я пытаюсь добавить пользовательский вид в заголовок каждого из разделов UITableView. Я использую этот метод делегата, чтобы вернуть желаемое представление. Он работает частично, поскольку он вызывает разделение секций клеток, как если бы там был заголовок, однако ни текст, ни UIButton на самом деле не появляются. Я знаю, что этот метод вызывается, когда я помещаю NSLog в метод, чтобы убедиться, что это так. Я делаю какую-то глупую ошибку, или это не правильный способ сделать это?Настройка пользовательского заголовка в UITableView
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView* customView = [[UIView alloc]initWithFrame:CGRectMake(0.0, 0.0, tableView.bounds.size.width, 44.0)];
customView.backgroundColor = [UIColor clearColor];
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 44.0)];
headerLabel.textColor = [UIColor darkGrayColor];
headerLabel.font = [UIFont boldSystemFontOfSize:16];
UIButton *headerButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// add button to right corner of section
return customView;
switch (section) {
case 0:
headerLabel.text = @"Team Name";
break;
case 1:
headerLabel.text = @"Captain";
break;
case 2:
headerLabel.text = @"Wicket Keeper";
break;
case 3:
headerLabel.text = @"Batting Order";
headerButton.center = CGPointMake(160.0, 22.0);
headerButton.backgroundColor = [UIColor blueColor];
headerButton.tag = section;
[headerButton addTarget:self action:@selector(enableCellReordering:) forControlEvents:UIControlEventTouchUpInside];
[customView addSubview:headerButton];
break;
default:
break;
}
[customView addSubview:headerLabel];
return customView;
}
Вы реализовали метод 'tableView: heightForHeaderInSection:' delegate? Это необходимо, если вы реализуете 'tableView: viewForHeaderInSection:'. – rmaddy
yes: 'return 44.0' – simonthumper
Почему вы возвращаете' customView' дважды? –