0

Ive been having problems with reloadData on a TableView. I've finally been able to establish that the variable I use to tell reloadData what to reload is resetting to NULL.

I've added the variable in ClassAppDelegate.h as follows:

@property (nonatomic, retain) id globalid;

and then synthesized in ClassAppDelegate.m as follows:

@synthesize globalid;

I then acces the variable in which ever class and method i need to use it with (in the method):

NDSClassAppDelegate *detailControllerAD = [[NDSClassAppDelegate alloc] init];

And then use it in this way to obtain the variable in that method:

NSLog(@"GlobalID at FetchTweets %@", detailControllerAD.globalid);

Why would my variable be resetting on reloadData?

Jimmypooza
  • 97
  • 2
  • 8

3 Answers3

2

You shouldn't be instantiating an app delegate object - your application is given one at launch as part of the UIApplicationMain() function, and it should live the lifetime of your application. Use [[UIApplication sharedApplication] delegate] to get the delegate, i.e. NDSClassAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]. Then, anywhere you need to set or read the globalid property, set it on this instance of the application delegate.

Instance variables (which properties are usually backed by) vary independently between instances of objects so you can't store a value in one object and then have the same value appear in another.

Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
0

When you use this NDSClassAppDelegate *detailControllerAD = [[NDSClassAppDelegate alloc] init]; new instance created of app delegate.

use this

[[UIApplication sharedApplication] delegate] to get existing instance of app delegate.

aBilal17
  • 2,974
  • 2
  • 17
  • 23
0

You can use above way to share the data throughout the application . I was also have same requirement in one of my previous application . At two three forum i have read about the sharing the data though out the application . But according to them this is not a good practice to store the data at application level because using app delegate as a model object is non delegate related stuff. So the cleaner approach is to use the singleton class . Create one singleton class to preserve all the variables state. That will be the cleaner approach .

V-Xtreme
  • 7,230
  • 9
  • 39
  • 79