Lucas Vallim da Costa
Lucas Vallim da Costa

Reputation: 203

iOS TableView not reloading if current view is tableViewController

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

This is the method from app delegate, and I need to reload the table view when a notification arrives.

How can I implement the reloadData, since Xcode won't accept if I write "[TableViewController.tableView reloadData];"?

Upvotes: 0

Views: 2163

Answers (4)

Abhishek
Abhishek

Reputation: 2253

//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];
 }

Upvotes: 4

Prabhat Kasera
Prabhat Kasera

Reputation: 1149

Please call this in app deligate within the call 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.
                }
}

Upvotes: 0

Saurabh Passolia
Saurabh Passolia

Reputation: 8109

use NSNotificationCenter postNotification: mechanism for posting a reloadTable notification which you can catch in your class having tableViewController by observer to fire reloadData for your tableview

Upvotes: 0

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

instead of TableViewController.tableView use [self.viewController.tableView reloadData];

If your current view Controller is not the tableView, consider using NSNotificationCenter to post a reload notification

Upvotes: 0

Related Questions