2013-04-30 86 views
-1

是的,我已经看过所有这个错误的其他职位。UITableView dataSource必须从tableView中返回一个单元格:cellForRowAtIndexPath:?

这是我的代码:我在哪里错了?

- (UITableViewCell *)TableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [_myTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

cell.textLabel.text = [_cellArray objectAtIndex: indexPath.row]; 
return cell; 
} 
+4

您的方法名称错误? tableView不是TableView – limon 2013-04-30 17:03:59

+0

哈哈,废话!谢谢 – Jason 2013-04-30 17:05:06

+0

我添加我的评论作为答案。请接受,如果这可以帮助你。 – limon 2013-04-30 17:13:46

回答

3

你的方法名是错误的。将TableView替换为tableView。为了防止这种错误,一旦你设置了数据源或委托,你应该使用control + Space,这样Xcode可以通过完成正确的方法名来帮助你。

1

问题是用这种方法名称:

- (UITableViewCell *)TableView:(UITableView *)myTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

将其替换为:

- (UITableViewCell *)tableView:(UITableView *)myTableView tableView:(NSIndexPath *)indexPath 

里边反实际的方法名是tableView:cellForRowAtIndexPath:没有TableView:cellForRowAtIndexPath:

相关问题