2013-12-14 49 views
1

在我的应用程序中,我有ViewController,它将TableView与静态单元格放在一起。故事板的外观喜欢这样的:TableView与静态单元格“... dataSource必须从cellForRowAtIndexPath返回一个单元格”错误

enter image description here

在.m文件我写道:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

[self.myTableView cellForRowAtIndexPath:indexPath]; 
    } 

但是我收到一个错误:dataSource must return a cell from cellForRowAtIndexPath 我做错了吗?

回答

1

你这样做是错误的 - 在该函数中你必须创建并返回一个单元格。

最常见的实现是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    return cell; 
} 

从我看到你想返回不同的细胞对不同行 - 比你要创建,如果该函数内部/ else块将出列适当的细胞类型具有独特每类型标识符。

如果你至少通过一个教程,这将是一件好事。这里是应该帮助你的那个:http://www.appcoda.com/customize-table-view-cells-for-uitableview/

+0

我只想让TabeView看起来像故事板,并且不要以编程方式创建某些东西。我只需要更改labels.text属性 – daleijn

+0

您不在* static * table视图中实现cellForRowAtIndexPath或任何数据源方法,请比较上面的“可能的重复”。 –

相关问题