2013-04-30 82 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:

相關問題