iphone – UITableView自定义单元格滚动后消失的内容
发布时间:2020-12-15 01:43:59 所属栏目:百科 来源:网络整理
导读:我已经看过很多次这里被问到这个问题,但没有一个解决方案对我有用.这是我的代码片段: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellClassName = @"DemoTableViewCell_s
我已经看过很多次这里被问到这个问题,但没有一个解决方案对我有用.这是我的代码片段:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellClassName = @"DemoTableViewCell_sched"; DemoTableViewCell_sched *cell = [tableView dequeueReusableCellWithIdentifier:CellClassName]; if (cell == nil) { NSArray *topLevelItems = [cellLoader instantiateWithOwner:self options:nil]; cell = [topLevelItems objectAtIndex:0]; } cell.fooData = [self.bugs objectAtIndex:indexPath.row]; return cell; } 然后我在ViewDidLoad中 cellLoader = [UINib nibWithNibName:@"DemoTableViewCell_sched" bundle:[NSBundle mainBundle]]; 解决方法
就我而言,发生的事情是我没有保持对tableview的dataSource的强大指针.因此,当滚动tableview时,数据源已经被释放并设置为nil,这导致tableview的numRowsForSection为0,而cellForRowAtIndexPath为nils.
如果有人遇到类似问题,您可能会查看是否正确保留了数据源和/或自定义对象. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |