Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

下拉刷新删除全部数据的话崩溃 #40

Closed
boboGoodMan opened this issue Feb 27, 2015 · 8 comments
Closed

下拉刷新删除全部数据的话崩溃 #40

boboGoodMan opened this issue Feb 27, 2015 · 8 comments

Comments

@boboGoodMan
Copy link

当在tabVIew 里在下啦刷新的方法里把所有数据全部删除的话,程序会崩溃;或者把所有数据全部删除,在从网络异步获取的话也会出问题。
*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit/UIKit-2935.138/UITableView.m:6509

@CoderMJLee
Copy link
Owner

从方法名可以看出:这是cell和数据处理问题,跟刷新框架没有关系的哈

@boboGoodMan
Copy link
Author

我看了一下,貌似是跟tabview冲突,您可以试一下在您的demo里单纯删除数据试一下

发送自魅族手机

-------- 原始邮件 --------
发件人:M了个J notifications@github.com
时间:周六 2月28日 11:57
收件人:CoderMJLee/MJRefresh MJRefresh@noreply.github.com
抄送:boboGoodMan guanjiangbo@126.com
主题:Re: [MJRefresh] 下拉刷新删除全部数据的话崩溃 (#40)

从方法名可以看出:这是cell和数据处理问题,跟刷新框架没有关系的哈


Reply to this email directly or view it on GitHub:
#40 (comment)

@CoderMJLee
Copy link
Owner

你删除完数据后,要进行reloadData或者reloadRows,这是tableView的正确用法哈。跟刷新框架没关系的

@boboGoodMan
Copy link
Author

[self.fakeData removeAllObjects];

// [self.tableView reloadData];
// [self.tableView headerEndRefreshing];

dispatch_async(dispatch_get_global_queue(0, 0), ^{
    for (int i = 0; i<5; i++) {
        [self.fakeData insertObject:MJRandomData atIndex:0];
    }
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
        [self.tableView headerEndRefreshing];

    });
});

我这样写的话是会出问题的

@CoderMJLee
Copy link
Owner

嗯,那也是数据处理的问题。你就算不用刷新框架,也还是有问题的。你的异步操作时间太短,导致插入数据和刷新表格的先后顺序不稳定。我先忙点东西哈,有问题等会一起讨论,你先留言哈。

@boboGoodMan
Copy link
Author

dispatch_async(dispatch_get_global_queue(0, 0), ^{
[self.fakeData removeAllObjects];
for (int i = 0; i<5; i++) {
[self.fakeData insertObject:MJRandomData atIndex:0];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
[self.tableView headerEndRefreshing];

    });
});

这样写的话就没有问题,如果我在工程里去重新获取数据,并且网速非常好的话,这样异步操作时间肯定也短,难道需要延时操作?

@CoderMJLee
Copy link
Owner

你的思路很正确,不用延迟的。其实一般的步骤就是去子线程拿数据,拿完数据就去主线程刷新。拿数据的话一般用的是异步请求框架,不用自己写gcd的dispatch_asyc代码

@boboGoodMan
Copy link
Author

3q,我貌似已经理通了,是我写的本身跟tabview的重用机制冲突了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants