Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Notify third ViewController that data has been loaded
I've been thinking for over a day regarding one dependence I came a cross. I am new in Objective-C, so please take it easy on me. I didn't know even how to google the problem I came across.
I have three classes: * RootViewController * HttpRequestWrapper * ManagementClass Where RootViewController inherits ManagementClass. (@interface RootViewController : ManagementClass ).
where the topViewController is the RootViewController (but later I want to change it for any topViewControlle at the moment).
[/HTML][/HTML]This function getTableData calls HttpRequestWrapper and in it URLConnection is called with its all delegates. But when it comes to the delegate method - (void)connectionDidFinishLoading:(NSURLConnection *)connection I want with NSNotification to notify the RootViewController that loading the data from the request is done and to populate the table with the data. But the NSNotification does not notify the RootViewController even tough it is a topViewController on the navigation stack.
So my question is how can I get the data back from the URLConnection to the RootViewController, even tough the request was initialized via the ManagementClass in a way.
Here is bit of code of my problem:
The class RootViewController:
#import \"RootViewController.h\" ......
// Get the data using the class HttpRequstWrapper (where I wrap the request in NSURLConnection) - (void) getTableData{ httpRequestWrapper = [HttpRequestWrapper alloc]; [httpRequestWrapper getXMLDataWithURL:[NSString stringWithFormat:@\"equipment/xml\"]]; } - (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated];
// Get Table Data [self getTableData]; }
- (void) populateTableData{
// Maybe change this line that error is shown if no data is found if (httpRequestWrapper.dataFromTheHttpRequest == nil){ NSLog(@\"Data got from the HttpRequestWrapper is nil or empty\"); }
// Parse the returned data xmlcont = [[XMLController alloc] loadXMLByURL:httpRequestWrapper.dataFromTheHttpRequest];
// Get the names of the Equipments as names of each Section arrayEquipments = [NSMutableArray alloc]; arrayEquipments = xmlcont.equipments; sectionsTitles = [[NSMutableArray alloc]init]; for (Equipment *eq in arrayEquipments){ [sectionsTitles addObject: eq.equipmentName]; }
// Reload the data in TableView [self.tableView reloadData]; }
} else if ([urlExtension rangeOfString: @\"equipment/xml\"].location != NSNotFound) { //[[self.navigationController topViewController] populateTableData]; - not working [[NSNotificationCenter defaultCenter] postNotificationName:@\"connectionFinishedLoading\" object:nil]; ....... }
I want in a way to make Controllers reusable as possible. I had an idea of putting [[self.navigationController topViewController] populateTableData] in connectionDidFinishLoading but the navigation Controller can't be called from the httpRequstWrapper, it simply does not executes. I still can't figure out why. I can only execute the navigationController methods whiten the ViewControrller of the View that is visible at the moment.
I see that you are posting a notificiation when connection finished, but I don't see anywhere that you registered to observe the notification in your RootViewController? So basically your notif is being called, but no one is listening..
I see that you are posting a notificiation when connection finished, but I don't see anywhere that you registered to observe the notification in your RootViewController? So basically your notif is being called, but no one is listening..
There is and observer in viewDidLoad, just scroll bit the code. - (void) viewDidLoad{ .... [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(populateTableData) name:@"connectionFinishedLoading" object:nil];
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThere is and observer in viewDidLoad, just scroll bit the code.
- (void) viewDidLoad{
....
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(populateTableData) name:@"connectionFinishedLoading" object:nil];
}
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome