gpt4 book ai didi

ios - 从 applicationWillEnterForeground 重新加载 TableView

转载 作者:行者123 更新时间:2023-11-28 21:56:00 25 4
gpt4 key购买 nike

当应用程序进入前台时,我尝试重新加载表格 View 。在 ViewController -> viewDidLoad:

[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(updateTableViewData:) name: @"UpdateTableViewAccueil" object:nil]; 

在ViewController中使用的方法:

-(void)updateTableViewData:(NSNotification *) notification
{
[self readMsgsFromDB];
[self reloadTableMsgsReceived];
}

在 appDelegate.m -> applicationWillEnterForeground

[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateTableViewAccueil" object: nil];

在我从 xcode 启动应用程序后,当应用程序第一次进入前台时,表格会重新加载,但下一次不会

你有什么建议吗?提前致谢

最佳答案

我在尝试在收到 NSNotification 时重新加载数据时遇到了类似的问题。似乎通知是在与主线程不同的线程中收到的。下面的代码帮助修复了它。

swift :

dispatch_async(dispatch_get_main_queue(), {self.tableView.reloadData()})

替换 self.tableView.reloadData() 使用您用来重新加载表格 View 的代码。

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

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