Может быть, у меня есть ответ на вашу проблему.Я не знаю, является ли это хорошим решением, но я думаю, что все в порядке.
Я создал новый пустой xib-файл и поместил UITableViewCell в этот файл.Я изменил высоту UITableViewCell на 54 и поместил UIView внутри UITableViewCell.Кадр вида 0,0,30,10.Затем я изменил владельца этого xib-файла на мой TableViewController.
@interface RootViewController : UITableViewController {
UITableViewCell * firstCellInSection;
}
@property (nonatomic, retain) IBOutlet UITableViewCell * firstCellInSection;
@end
После этого я подключил выход FirstCellInSection с моим UITableViewCell в xib-файле.
Затем я изменил код, который TableView загружает этот firstCell для всех ячеек с
indexPath.row == 0
Вот код:
@synthesize firstCellInSection;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell;
if (indexPath.row == 0) {
if (indexPath.row == 0) {
static NSString *firstCellInSectionIdentifier = @"FirstCellInSectionIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:firstCellInSectionIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"FirstCell" owner:self options:nil];
cell = firstCellInSection;
self.firstCellInSection = nil;
}
}
}
else {
static NSString *CellIdentifier = @"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
}
// Configure the cell.
return cell;
}
Пользовательская высота строки:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) return 54;
else return 44;
}
В сочетании с вашим кодом для headerView это может выглядеть так, как вы хотите.