Object stored in the app delegate doesn't seem to persist

Go To StackoverFlow.com

0

Perhaps I'm misunderstanding how this should work, but I've created an object in the app delegate, and on a tab bar controller I set the object, but when I go to the other tabs it doesn't seem to exist anymore.

This is the only place I reference it in the app delegate.

AppDelegate.h

@property (strong, nonatomic) Encounter *encounter;

AppDelegate.m

@synthesize encounter;

Here is where I set it on the first page of the tab controller. This is the only time it's referenced on the intial tab controller view. The loadEncounter method is simply passing it the json results from the web api. Then I load set the values of the views labels.

ehrxAppDelegate *app = [[UIApplication sharedApplication]delegate];
app.encounter = [[Encounter alloc] init];
[app.encounter loadEncounter:result];

nameLabel.text = app.encounter.subscriber_name;
locationlabel.text = app.encounter.location_name;
dateLabel.text = app.encounter.encounter_time;
genderLabel.text = app.encounter.subscriber_gender;
dobLabel.text = app.encounter.subscriber_dob;
statusLabel.text = app.encounter.admission_status;
detailsLabel.text = app.encounter.details;

This is how I access it on the second view in the tab controller. I was under the impression that since I set it's value on the first view I could just grab it on the second view and use it again.

ehrxAppDelegate *app = [[UIApplication sharedApplication]delegate];
self.encounters = app.encounter.encounters;

[self.tableView reloadData];
2012-04-05 18:52
by Jhorra


0

Does app.encounter.encounters work in the first view. Since you can still access app.encounter it seems that the object persists ok across your vire controllers. So maybe there is an issue with encounter.encounters variable.

How did you set encounters ?

2012-04-05 19:07
by Alex L
This wasn't exactly it, but it was so dumb. I didn't actually finish setting up the table on the view I was displaying them on, that's why they weren't showing - Jhorra 2012-04-05 19:43
Ads