gpt4 book ai didi

iphone - 如果当前 View 是 tableViewController,iOS TableView 不会重新加载

转载 作者:行者123 更新时间:2023-11-28 19:17:40 24 4
gpt4 key购买 nike

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
// Handle the notificaton when the app is running

NSLog(@"Recieved Notification %@",notif);

NSLog(@"local notifications count = %d", [[[UIApplication sharedApplication] scheduledLocalNotifications] count]);
}

这是来自应用程序委托(delegate)的方法,我需要在通知到达时重新加载 TableView 。

我该如何实现 reloadData,因为如果我写“[TableViewController.tableView reloadData];”,Xcode 不会接受?

最佳答案

//Just do one thing, as you got the notification , post on more notification as follows in the method ....

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {

[[NSNotificationCenter defaultCenter] postNotificationName:@"RELOAD_DATA"object:nil];
}

//the add observer in viewDidLoad of that view controller where your table is added..

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

//and make a method in the same class

- (void)receiveTableNotification:(NSNotification *)pNotification{
[your_table_view reloadData];
}

//now remove obser in dealloc in your view controller class where you add observer ..

- (void) dealloc
{

[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}

关于iphone - 如果当前 View 是 tableViewController,iOS TableView 不会重新加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11202515/

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