社区
iOS
帖子详情
reloadData方面问题,请大神帮忙看看
nicookly
2014-09-22 04:43:53
加精
didSelectRowAtIndexPath中调用一次[self.tableview reloadData] 后, 且 numberOfRowsInSection的返回值为1,却调用了两次cellForRowAtIndexPath,也创建了两次cell,且只显示一行(cell是用xib 实现的自定义cell)?????求解,急,大神如果知道,还请赐教。
...全文
1568
15
打赏
收藏
reloadData方面问题,请大神帮忙看看
didSelectRowAtIndexPath中调用一次[self.tableview reloadData] 后, 且 numberOfRowsInSection的返回值为1,却调用了两次cellForRowAtIndexPath,也创建了两次cell,且只显示一行(cell是用xib 实现的自定义cell)?????求解,急,大神如果知道,还请赐教。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
15 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
Java 狂魔
2014-09-28
打赏
举报
回复
很好,很有用,谢谢。
nettman
2014-09-24
打赏
举报
回复
CodeC
2014-09-24
打赏
举报
回复
为什么就不给一个机会,自己强大才能保护他人
程老师2088
2014-09-23
打赏
举报
回复
应该是有别的地方重复调用了。。楼主仔细检查下
laoer_2002
2014-09-23
打赏
举报
回复
还是要好好学习
wanruochuwenyy
2014-09-23
打赏
举报
回复
好高端的样子啊 完全不懂啊
hugh_z
2014-09-23
打赏
举报
回复
learning
ReyZhang
2014-09-23
打赏
举报
回复
断点看一下numberOfRowsInSection 这个代理方法执行几次?如果也执行了两次,可以确定重载了两次数据。还是仔细检查一下。
Bannings
2014-09-22
打赏
举报
回复
你在cellForRowAtIndexPath方法里下断点,能看到两次调用的时机么
nicookly
2014-09-22
打赏
举报
回复
引用 1 楼 zhangao0086 的回复:
是不是在其他的地方也有调用的代码?或者tableView有几个实例?
我也只是 触发单击事件里 调用了 reloadData 而且是在viewDidLoad 中创建的tableView。
nicookly
2014-09-22
打赏
举报
回复
引用 2 楼 hantianjie_ 的回复:
代码贴出来看看
代码 已贴出
nicookly
2014-09-22
打赏
举报
回复
只在viewDidLoad中创建了一个 tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 110,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height - 110) style:UITableViewStylePlain]; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *TableSampleIdentifier = @"TableSampleIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableSampleIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableSampleIdentifier]; //在添加cell时添加边线框 UIView *backView = [[UIView alloc] initWithFrame:cell.frame]; backView.layer.masksToBounds = YES; backView.layer.cornerRadius = 1.0; backView.layer.borderWidth = 1.0; backView.layer.borderColor = [[UIColor lightGrayColor] CGColor]; [cell addSubview:backView]; } if (_chapterList.count == 2) { NSLog(@"sdasdasdsdasd111111111111"); } NSUInteger row = [indexPath row]; cell.textLabel.text = [[_chapterList objectAtIndex:row]objectForKey:@"type_name"]; return cell; } ================= - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row = [indexPath row]; //这部分解析xml 的 self startParseQuestion:[[_chapterList objectAtIndex:row] objectForKey:@"id"] ]; [_questionList removeAllObjects]; // 将解析到的数据放入_questionList中 [_questionList addObjectsFromArray:[myPlayer questionDataArray]]; if (_questionList.count == 0) { UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示" message:@"该部分内容正加紧录制中,敬请期待!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alter show]; } else { [self.tableview reloadData]; } } ============ -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (isQuestion != NO) { NSLog(@"_questionList.count::::%d",_questionList.count); return _questionList.count; } else { NSLog(@"_chapterList.count::::::%d",_chapterList.count); return _chapterList.count; } }
hantianjie_
2014-09-22
打赏
举报
回复
代码贴出来看看
Bannings
2014-09-22
打赏
举报
回复
是不是在其他的地方也有调用的代码?或者tableView有几个实例?
iOS UITableView
reload
Data
问题
总结
本文总结了在iOS开发中遇到UITableView
reload
Data
方法无效或不执行的
问题
,包括未设置代理、非主线程刷新数据、数据源变更不在主线程以及在错误的对象上调用
reload
Data
等常见原因,并提供了相应的解决方案。通过理解这些
问题
,有助于提升iOS应用中表格视图的正确刷新与更新。
由UITableView
reload
Data
后引起的界面布局
问题
分析
在iOS开发中,调用UITableView的
reload
Data
方法后,若立即设置contentOffset可能导致界面布局
问题
。本文分析了当cell数量变化时,tableView内容偏移量清零的动画过程与自定义动画冲突,导致布局偏差的状况,并提出了解决方案:关闭动画或在动画回调中设置contentOffset。
UITableView
reload
Data
的正确方法。
请
每一个开发者必看。
本文探讨了在tableView滚动过程中调用
reload
Data
可能导致的App崩溃
问题
,并提出了两个解决方案。通过确保
data
Source更改和
reload
Data
操作都在主线程中进行,并在
data
Source更改后立即调用
reload
Data
,可以避免此类崩溃。
UITableView
Reload
Data
那些坑
探讨Swift中TableView使用
reload
Data
方法的异步行为,及其对UI更新的影响。文章深入解析了在调用此方法后,代理方法如numberOfRowsInSection、cellForRowAt并非立即执行的
问题
,并提供了解决方案,通过添加layoutIfNeeded强制TableView立即布局,确保UI同步更新。
iOS开发:UICollectionView的
reload
Data
失效
问题
本文讲述了在iOS应用中Objective-C开发过程中,UICollectionView的
reload
Data
方法失效
问题
,重点在于解决数据模型共享导致的cell更新
问题
,以及如何通过调整代码逻辑、加入主线程和避免重复赋值来确保正确刷新。
iOS
29,040
社区成员
12,459
社区内容
发帖
与我相关
我的任务
iOS
主要讨论与iOS相关的软件和技术
复制链接
扫一扫
分享
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章