gpt4 book ai didi

ios - 无法从数据源获取单元格

转载 作者:行者123 更新时间:2023-11-30 12:41:45 25 4
gpt4 key购买 nike

下面的代码有什么问题

-(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>)'

我已经为 TableView 设置了委托(delegate)和数据源

最佳答案

使用 Swift 3,当我忘记将 UITableViewDataSource 和 UITableViewDelegate 协议(protocol)添加到 ViewController 声明中时,我遇到了此错误。

类DataViewController:UIViewController,UITableViewDataSourceUITableViewDelegate

添加它们解决了问题。

关于ios - 无法从数据源获取单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42162846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com