gpt4 book ai didi

iphone - TableView 未从 NSNotification 重新加载

转载 作者:行者123 更新时间:2023-12-03 17:32:35 25 4
gpt4 key购买 nike

我在使用 NSNotification 重新加载 tableView 时遇到了一些问题。

我的设置是,我有一个过滤器 View ,允许用户将过滤器应用到 TableView ,一旦他们单击更改过滤器,我将发送一个 NSNotification,该通知会在 AppDelegate 中拾取,然后重新加载核心应用过滤器作为谓词的数据。

从核心数据加载数据后,我会向 tableView 发布另一个通知,告诉它重新加载数据。

使用 NSLog,我可以看到通知正在发送和接收,尽管 [self.tableView reloadData] 没有执行任何操作。

这是我重新加载数据的函数:

-(void)reloadTable:(NSNotification *)notification {
NSLog(@"reloading table");
[self.rootTableView reloadData];
}

当 Controller 当前处于 View 中时,以相同的方式从 Controller 内部调用重新加载效果很好,所以我很困惑为什么这不起作用。

最佳答案

通知是否到达主线程以外的线程?如果通知是从后台线程发送的。如果是这种情况,您需要将 reloadData 调用编码到主线程。像这样的事情:

[tableView performSelectorOnMainThread: @"reloadData" withObject:nil waitUntilDone:NO];

关于iphone - TableView 未从 NSNotification 重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4737833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com