0
我真的想通过使用Interface Builder在XIB中进行布局来完全控制节头。无法从XIB加载viewForSectionHeader
我正在使用下面的代码,但是我的titleLabel.text在我运行应用程序时没有改变。它继续显示每个节标题的默认“标签”文本。我已经NSLog'd headerText的值,它包含正确的字符串。
任何想法?谢谢
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
CustomSectionHeaderViewController *cshvc = [[CustomSectionHeaderViewController alloc] initWithNibName:@"CustomSectionHeaderViewController" bundle:nil];
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
NSString *headerText = [NSString stringWithFormat:@"%@", [sectionInfo name]];
cshvc.titleLabel.text = headerText;
return cshvc.view;
}
使用答案更新: 下面是我把它读Tammo的回答
CustomSectionHeader *cshv = [[[NSBundle mainBundle] loadNibNamed:@"CustomSectionHeader" owner:self options:nil]objectAtIndex:0];
id <NSFetchedResultsSectionInfo> sectionInfo = [[fetchedResultsController sections] objectAtIndex:section];
NSString *headerText = [NSString stringWithFormat:@"%@", [sectionInfo name]];
cshv.textLabel.text = headerText;
return cshv;
您是否将'titleLabel'属性连接到Interface Builder中的标题标签? –
是的,它已正确连接 – sayguh