【问题标题】:Custom tableview section header with storyboard and got error?带有情节提要的自定义表格视图部分标题并出现错误?
【发布时间】:2013-05-17 14:39:39
【问题描述】:

如果我 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;
}

【问题讨论】:

  • 请发布您的部分标题代码。

标签: iphone storyboard uitableview


【解决方案1】:

实际上,如果您查看链接 pedro.m 的帖子中的 cmets,就会给出一个可能的解决方案。他向他调用 contentView 的单元格添加了一个子视图,然后将其返回。

我做的比较简单:

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

这为我解决了错误。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 谢谢其实我这样做了,我只是想用storyboard自定义headerView,最后我放弃并使用代码来初始化header view
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 2013-09-30
    • 2012-07-22
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    相关资源
    最近更新 更多