我想使用IB在单独的.xib中创建自定义标题部分视图
但是在IB中我找不到组件UITableViewHeaderFooterView(类似于UITableViewCell)并为其分配重用
那么如何在自定义标题部分创建?
我创建了一个继承自UITableViewHeaderFooterView的MySection类创建.xib,MySection.xib注册xib以便重用单元格
问题是,如何使用initWitReuseIdentifier ....
出于性能考虑,通常会重用UITableView的单元格.有没有办法用TableView标题'视图做同样的事情?我在谈论用委托方法返回的那些:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
我尝试执行以下操作,但似乎没有按预期工作:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
static NSString *CellIdentifier = @"Header";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell == nil) {
cell = [self getHeaderContentView: CellIdentifier];
}
return cell;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法重用标题'的观点?
我已经创建了一个自定义的UITableViewHeaderFooterView并成功从nib加载到我的UITableView中,但始终收到此消息
"不推荐在UITableViewHeaderFooterView上设置背景颜色.请改用contentView.backgroundColor."
这里加载我的自定义UITableViewHeaderFooterView的代码:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
KTHeaderFooterViewIphone customHeaderIphone* = [[[NSBundle mainBundle] loadNibNamed:@"KTHeaderFooterViewIphone" owner:self options:nil] objectAtIndex:0];
customHeaderIphone.tintColor = [UIColor whiteColor]; // this code worked, but the message above always show
customHeaderIphone.contentView.backgroundColor = [UIColor redColor]; // this code doesn't work, nothing's happened
customHeaderIphone.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"customHeader.png"]]; // this code doesn't work too, I can't change custom background image
return customHeaderIphone;
Run Code Online (Sandbox Code Playgroud)
}