0
- (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]);
}

这是来自应用委托的方法,当通知到达时我需要重新加载表格视图。

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

4

4 回答 4

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];
 }
于 2012-06-26T07:59:10.150 回答
0

而不是TableViewController.tableView使用[self.viewController.tableView reloadData]

如果您当前的视图控制器不是 tableView,请考虑使用NSNotificationCenter发布重新加载通知

于 2012-06-26T07:27:35.117 回答
0

使用NSNotificationCenter postNotification:机制来发布 reloadTable 通知,您可以在具有 tableViewController 的类中捕获该通知observer以触发reloadData您的 tableview

于 2012-06-26T07:29:00.360 回答
0

请在回调函数中的 app deligate 中调用它

- (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.
                }
}
于 2012-06-26T07:38:38.610 回答