看代码:
#viewDidLoad
[self getActivityListFromNetwork];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(refreshActivityListFromNetwork)
name:@"backRefresh"
object:nil];
#refreshActivityListFromNetwork
- (void)refreshActivityListFromNetwork{
[self.dataArray removeAllObjects];
[self getActivityListFromNetwork];
[self.mainTableView headerEndRefreshing];
}
问题是:如果注销后重新登录的话会有一定概率出现重复数据。
分析原因是点击登录后,页面加载执行了getActivityListFromNetwork这个方法。这时候去请求数据。在没有返回数据前执行了refreshActivityListFromNetwork又一次去请求了数据。导致两次请求获得的数据都加载出来了。。。
伊谢尔伦2017-04-18 09:55:42
Execute removeAllObjects and reloadData after each data request is successful. In addition, it is best to provide a corresponding caching mechanism for your network request method. When there is no new data, there is no need to update the data source.
巴扎黑2017-04-18 09:55:42
Why is it not executed after the network request comes back to obtain the data[self.dataArray removeAllObjects];
?
黄舟2017-04-18 09:55:42
I agree with you upstairs, the data source removeAllObjects should be placed in the successful network request
高洛峰2017-04-18 09:55:42
Um, why are you writing it in such a disgusting way? Agent, block deserves your own