2012-06-26 20 views
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]); 
} 

這是來自應用程序委託的方法,我需要在通知到達時重新載入表視圖。如果當前視圖是tableViewController,則不會重新載入iOS TableView

我該如何實現reloadData,因爲如果我編寫「[TableViewController.tableView reloadData]」,Xcode將不會接受;

回答

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]; 
} 
中調用此
+0

Bingo !!!!!!!男人,你剛剛解決了我現在想要的一個星期的問題。超級謝謝你。真。我無法解釋我現在有多開心。 –

+0

你的歡迎...總是開心:) – Abhishek

+0

很棒..保存了很多時間。我花了1天半... – wasim

0

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

如果當前視圖控制器不是的tableView,可以考慮使用NSNotificationCenter張貼重裝通知

+0

你可以給我發一個這樣的例子嗎?我是新來的iOS –

+0

你嘗試使用這個[self.viewController.tableView reloadData]? –

+0

是的,當我寫[self.TableViewController.tableView reloadData] Xcode給我「在'AppNameAppDelegate'類型的對象上找不到'propery'TableViewController' –

0

使用NSNotificationCenter postNotification:機制張貼reloadTable通知,您可以通過observer具有tableViewController類趕上火reloadData您實現代碼如下

+0

對不起,請給我一個代碼示例? –

0

請應用deligate通話backfunction

- (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. 
       } 
} 
+0

我是否完全按照它在這裏? –

+0

您需要進行更改....根據您的類名和tableviewcontroller名稱 –

+0

問題是Xcode不會接受我的tableView名稱。WHen I寫[自我TableViewController]我得到錯誤說沒有這樣的公關operty exists –

相關問題