tableView调用reloadData不刷新, cellForRowAtIndexPath方法不走

http://blog.sina.com.cn/s/blog_6451df3d0102vrrz.html

记录一下蛋疼的bug.

我用AFNetworking 做网络请求,回调成功后 执行[self.tableView reloadData] 二次刷新界面;  但是numberOfRows走,cellForRowAtIndexPath 方法却不走了.

stackOverFlow上说在主线程刷新界面就好了,这样:
              dispatch_sync(dispatch_get_main_queue(), ^{
                    [self.tableView reloadData];
              });
我这样写程序直接假死了.

之后继续尝试以下方法, 依然无法刷新:
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationF ade];  
 [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];

甚至拿到cell直接赋值都不行.

         ChatListCell *cell = (ChatListCell *)[self.tableViewcellForRowAtIndexPath:indexPath];

         

         if (model.avatar)

         {

             cell.imageURL kImageURLWith(model.avatar);

         }

         if (model.user_nicename)

         {

             cell.name = model.user_nicename;

         }

一度无语,觉得只能用调[self viewDidLoad]  刷新界面了. 同时猜测可能是self.tableview的创建有问题.

本来的tableview是通过懒加载创建的的:

- (UITableView *)tableView

 {

    if (_tableView == nil) {

        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];

          _tableView.delegate self;

        _tableView.dataSource self;

 }

return _tableView;

}

然后  [self.view addSubview:self.tableview] 添加到视图上;


最后尝试了下改成下边的就好了,创建视图的时候就添加.原因未知,其他地方保持上边的写法并没有问题:

- (UITableView *)tableView

 {

    if (_tableView == nil) {

        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];

          _tableView.delegate self;

         _tableView.dataSource self;

 [self.view addSubview:_tableView];

 }

 return _tableView;

}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值