Note that there are some explanatory texts on larger screens.

plurals
  1. POAppDelegate property being reset between viewControllers
    primarykey
    data
    text
    <p>I'm trying to share data between various viewControllers, I'm using a property declared in the appDelegate. I set the property in my first viewController and when I print out the contents, everything looks fine, but after I call a custom class method, the property gets set to some random value that seems to change every time I run the app. See code below:</p> <p>appDelegate .h</p> <pre><code>NSDate *lastUpdated; @property (nonatomic, retain) NSDate *lastUpdated; </code></pre> <p>viewController .m</p> <pre><code>AppDelegateClassName *appDelegate = (AppDelegateClassName *)[[UIApplication sharedApplication] delegate]; [appDelegate setLastUpdated:[NSDate date]]; </code></pre> <p>After I set the property, I then call the following custom class method with a reference to the viewController as a parameter:</p> <p>viewController .m</p> <pre><code>ForceData *forceData = [[ForceData alloc] init]; [forceData queryServiceWithParent:self]; </code></pre> <p>If I try and display the contents of the appDelegate property within my custom class, it returns a random value. Once the custom class returns to the viewController, the appDelegate property stays as the random value.</p> <p>I can't see what's going wrong. Can anyone help?</p> <p>Thanks.</p> <p>UPDATE</p> <p>Here is the code within the queryServiceWithParent method:</p> <pre><code>- (void)queryServiceWithParent:(UIViewController *)controller { viewController = (ForcesTableViewController *)controller; responseData = [[NSMutableData data] retain]; NSString *url = [NSString stringWithFormat:@"http://example.com"]; theURL = [[NSURL URLWithString:url] retain]; NSURLRequest *request = [NSURLRequest requestWithURL:theURL]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; } </code></pre> <p>I'm still having this problem so any help is much appreciated.</p> <p>UPDATE:</p> <p>I've spent some more time looking at this and I can display the contents of lastUpdated anywhere within the queryServiceWithParent (just above) and it displays fine. But if I display the same property in the connectionDidFinishLoading, it's reset. Very stuck with this one!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload