【问题标题】:custom uitableViewCell in controller which inherit from UITableViewController从 UITableViewController 继承的控制器中的自定义 uitableViewCell
【发布时间】:2011-05-06 05:27:29
【问题描述】:

我想创建自定义 UiTableViewCell,当我创建 TableView 时,它可以工作,就像在这个 example 中一样,继承自 UIViewController。但是当我创建从 UITableViewController(不是 UIViewController)继承的控制器,并在 xib 中创建 UITableViewCell,当然连接 IBOutlet 时,我得到了这个错误:

*** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m:5678

2011-05-06 07:21:34.107 tabela[11424:207] * 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView:cellForRowAtIndexPath 返回一个单元格:'

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return cellOne; }

【问题讨论】:

  • 一小时前有人问过这个问题:stackoverflow.com/questions/5906592/…。简短的故事是,以编程方式(而不是在 IB 中)制作您的自定义 UITableViewCell。
  • 显示您的 cellForRow 代码

标签: iphone uitableview


【解决方案1】:

这是示例参考

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// In your case it has to be the custom cell object here.
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AnIdentifierString"];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"AnIdentifierString"] autorelease];
    }

    cell.textLabel.text = @"This text will appear in the cell";


    return cell;
}

【讨论】:

  • 是的,我知道,但我只想检查这是否有效,所以我写道: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { return cellOne; } cellOne 当然是挂了
  • 是的,我知道这是可行的,有数百种方法可以创建自定义的 uitableviewCell,但我想知道为什么我的实现不起作用。
猜你喜欢
  • 2013-06-10
  • 1970-01-01
  • 1970-01-01
  • 2012-12-17
  • 1970-01-01
  • 2011-12-06
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
相关资源
最近更新 更多