我在Storyboard中添加了一個TableViewController,並將其類型更改爲繼承UITableViewController的自定義類。 我還在故事板中添加了一些單元格。 (不是自定義的,基本的UITableViewCells) 現在我想以編程方式修改這些單元格(如有條件地添加披露指示符)。所以,我做了我的班採取的UITableViewDelegate,但是當我嘗試以編程方式修改我的單元格的文本,我得到這個錯誤:無法從其dataSource中獲取單元格 - 故事板和代碼
NSInternalInconsistencyException : failed to obtain a cell from its dataSource
下面是代碼:
@interface MyTableViewController() <UITableViewDelegate>
@end
@implementation MyTableViewController
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.text = @"test";
return cell;
}
@end
在我的故事板,在引用出口,我正確地有dataSource和委託鏈接到表視圖。 我在這裏錯過了什麼?感謝您的幫助
您正在調用'[tableView cellForRowAtIndexPath:indexPath]'?這不是要調用的方法。調用'UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@「someCellID」forIndexPath:indexPath];' – Larme
對於您的表格視圖內容,您使用的是動態原型還是靜態單元格? –
@Larme謝謝你的回覆。我嘗試在我的故事板中設置標識符「TestCell」,並用'dequeueReusableCellWithIdentifier'替換了'cellForRowAtIndexPath',但現在我得到這個錯誤:'無法使標識符TestCell出隊 - 必須爲標識符註冊一個筆尖或類,連接故事板中的原型單元格 – Someday