MJRefresh
MJRefresh copied to clipboard
刷新时数据会越界。
感谢杰哥搞出这么好的一个框架,一直在用,现发现一个问题,不知是不是MJRefresh的问题。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell=[self mergeData:self.dataArr[indexPath.row]];
return cell;
}
当我进行分页获取数据时,dataArr中会有超过一页的数据,当翻到第二页后,我下拉刷新想重新获取第一页的最新数据时,则有时候会数据越界,这个indexPath.row的值会超过dataArr的总长度,现在只能这样做,我不知是不是我的问题还是MJRefresh问题。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
long rowIndex=indexPath.row;
if (rowIndex>=self.dataArr.count) {
rowIndex=self.dataArr.count-1;
}
UITableViewCell *cell=[self mergeData:self.dataArr[rowIndex]];
return cell;
}
按照我的经验,数组越界跟MJRefresh没有关系的哈,框架内部从来不涉及数组操作。你再检查一下访问数组的其他代码
连续多次刷新,会有概率导致数组越界的!挺奇怪的!

提前判断 if(indexpath.row < array.count)