【发布时间】:2016-03-18 23:07:22
【问题描述】:
下面的代码有什么问题
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = @"hello";
return cell;
}
还有
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 2;
}
但我无法从其数据源获取单元格
整个异常是
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (<UITableView: 0x7ffe0b092800; frame = (0 97; 414 590); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x7ffe0acf3b10>; layer = <CALayer: 0x7ffe0aceb6e0>; contentOffset: {0, 0}; contentSize: {414, 88}>) failed to obtain a cell from its dataSource (<AllContactsViewController: 0x7ffe0ace60f0>)'
我已经为表格视图设置了委托和数据源
【问题讨论】:
-
您是否注册了该重用标识符(在您的故事板中?)。如果不是,那么
dequeueReusableCellWithIdentifier可能会返回 nil,那么您有责任分配一个新单元格并返回该单元格
标签: ios objective-c uitableview