自定义uitableview部分标题与故事板并得到错误?

时间:2013-05-22 13:50:03

标签: iphone storyboard uitableview

如果我add custom uitableView sectionheader using storyboard我收到此错误AX ERROR: Could not find my mock parent, most likely I am stale.此错误意味着什么,我该如何解决?标题代码:

 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    static NSString *cellID = @"sectionHeaderID";
    UITableViewCell *headerview = [tableView dequeueReusableCellWithIdentifier:cellID];
    return headerview;
}

2 个答案:

答案 0 :(得分:4)

节标题与表格视图单元格不同。您应该为标题视图创建自己的UIView,而不是从表视图单元格中获取它。例如:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerview = [[UIView alloc] initWithFrame:CGRectMake(0,0,CGRectGetWidth(self.view.frame), 100.0)];
    return headerview;
}

答案 1 :(得分:4)

实际上,如果你查看你链接pedro.m的帖子中的评论,给出一个可能的解决方案。他在他调用contentView然后返回它的单元格中添加了一个子视图。

我做的更简单:

 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    static NSString *cellID = @"sectionHeaderID";
    UITableViewCell *headerview = [tableView dequeueReusableCellWithIdentifier:cellID];
    return headerview.contentView;
}

这为我解决了错误。