问题: UITabelView 使用scrollToRowAtIndexPath: atScrollPosition: animated:时 滚动列表 没有滚动到我们想滚动的位置。
在开发IM 系统时,遇到一个问题。自己发送消息时,聊天信息滚动到最下面,但是有时只滚动一部分,并没有
达到我们想要的效果。为什么有的时候可以有的时候不可以。原来发送消息后,后台会返回一个消息发送成功的
回调,在回调中更新消息的状态,由于scrollToRowAtIndexPath 滚动动画需要一定时间,收到回调更新消息的时候滚动
动画还没有完成,导致的这个问题。
解决方法:在回调用中延迟更新消息的状态。
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^
{
//解决单独刷新某一cell,tableView 上下滚动闪的问题
[UIView performWithoutAnimation:^
{
NSInteger row = [weakSelf.messageArray indexOfObject:tempModel];
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:row inSection:0];
[weakSelf.chatTable reloadRowsAtIndexPaths: [NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
}];
});