Reputation: 21
I have a question concerning iOS. I couldn't find an answer to my question online but maybe one of you know the answer. Im working on an app which pulls data from an online database. A NSObject Class is called by a timer in the background of the app. I want it to tell one of my view controller to reload its tableview if it finds new data. Like it is supposed to check for data not caring in which view controller im in. But when I'm in the specific one with my table view it should reload the table view if it found new data. I've tried to create an instance of the tableviewcontroller in my NSObject and call the reload table view function front there, but that doesn't work :/ I apologise for my poor explanation, I'm not a native speaker.
Thank you very much :)
Upvotes: 0
Views: 494
Reputation: 1855
You can use two approaches:
I would go with the first option:
a. in your data loading class:
NSNotification *notification = [NSNotification notificationWithName:@"newDataFetched" object:anyObject];
[[NSNotificationCenter defaultCenter] postNotification:notification];
b. in your listener class:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(aMethodToReloadTheTableView:)
name:@"newDataFetched"
object:nil];
Upvotes: 1