繁体   English   中英

继承自UITableViewController的控制器中的自定义uitableViewCell

[英]custom uitableViewCell in controller which inherit from UITableViewController

我想创建自定义的UiTableViewCell,并且在创建TableView时(如本示例中所示 )通过继承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 dataSource必须从tableView:cellForRowAtIndexPath返回单元格:”

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

这是样本参考

- (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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM