2011-07-07 122 views
1

myaI有這樣的代碼:IOS:委託方法有兩個的tableView

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


if (tableView == firstTableView){ 

static NSString *CellIdentifier = @"Cell"; 

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

cell.textLabel.text = [myArray objectAtIndex:indexPath.row]; 

return cell; 
} 
} 

我檢查的tableview是firsttableview,但它給我一個警告,因爲該方法沒有「返回」細胞,我怎麼能解決?

+0

我不明白你要做什麼。 「這個方法沒有'返回單元'」是什麼意思? –

回答

1

如果表格爲firstTableView,則只返回一個單元格。確保通過在條件之外添加return語句來爲其他表返回單元格。

1

您的代碼需要返回通過該方法的所有路徑的值。因此,如果您檢查firstTableView失敗,您仍然需要從該方法返回有效的UITableViewCell。您應該閱讀UITableView programming guide - 它會引導您正確使用tableview。