gpt4 book ai didi

ios - 应用程序退出 *** 断言失败 -[UITableView _configureCellForDisplay :forIndexPath:]

转载 作者:行者123 更新时间:2023-11-28 18:29:49 24 4
gpt4 key购买 nike

这是我的 UITableView 代码。每当我加载 View 时,都会收到以下错误:

*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:7962 UITableView (; layer = ; contentOffset: {0, 0}; contentSize: {343, 190}>) failed to obtain a cell from its dataSource ()

创建表的方法是一样的。我已经使用 tableviews 很长时间了。但是,我无法弄清楚这有什么问题。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
switch (indexPath.row) {
case 0:
return 70;
break;
case 1:
return 50;
break;
case 3:
return 50;
break;
default:
return 70;
break;
}
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *Id = @"CellID2";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:Id forIndexPath:indexPath];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Id];
}

UILabel *object = (UILabel *)[cell.contentView viewWithTag:1];
UILabel *discription = (UILabel *)[cell.contentView viewWithTag:2];
object.text = [array objectAtIndex:indexPath.row];

switch (indexPath.row) {
case 0:
discription.text = self.Location;
break;
case 1:
discription.text = self.LocationType;
break;
case 3:
discription.text = self.rating;
break;
default:
break;
}

return nil;
}

最佳答案

讯息:

failed to obtain a cell from its dataSource

意味着您将为您的 cellForRowAtIndexPath 方法返回 nil

cellForRowAtIndexPath 方法的末尾将 return nil; 更改为 return cell;

关于ios - 应用程序退出 *** 断言失败 -[UITableView _configureCellForDisplay :forIndexPath:],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35236879/

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