reloadData方面问题,请大神帮忙看看

nicookly 2014-09-22 04:43:53
加精
didSelectRowAtIndexPath中调用一次[self.tableview reloadData] 后, 且 numberOfRowsInSection的返回值为1,却调用了两次cellForRowAtIndexPath,也创建了两次cell,且只显示一行(cell是用xib 实现的自定义cell)?????求解,急,大神如果知道,还请赐教。
...全文
1504 15 打赏 收藏 转发到动态 举报
写回复
用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有几个实例?

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧