- (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]);
}
这是来自app delegate的方法,我需要在通知到达时重新加载表视图。
如何实现reloadData,因为如果我写“[TableViewController.tableView reloadData]”,Xcode将不接受?“
答案 0 :(得分:4)
//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];
}
答案 1 :(得分:0)
而不是TableViewController.tableView
使用[self.viewController.tableView reloadData]
;
如果您当前的视图控制器不是tableView,请考虑使用NSNotificationCenter
发布重新加载通知
答案 2 :(得分:0)
使用NSNotificationCenter postNotification:
机制发布reloadTable通知,您可以通过observer
在您的类中捕获tableViewController,以便为您的tableview触发reloadData
答案 3 :(得分:0)
请在回调函数
中的app delegate中调用此方法- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
UINavigationController *navControl = [[[self tableViewController] viewControllers] objectAtIndex:lastObject]; //
id Obj = [[navControl viewControllers] lastObject];
if([Obj isKindOfClass:[Required class]])
{
[Obj reloadDataOfTable];// made an function to desired class.
}
}