Note that there are some explanatory texts on larger screens.

plurals
  1. POError While referencing AppDelegate
    primarykey
    data
    text
    <p>I have an App Delegate and a 3 view controllers in my project. I have a variable(a NSMutable Array) in my App Delegate which I want to access from my view controllers. So I decided to create a pointer to my App Delegate and access the variables. Here is my code:</p> <pre><code>iSolveMathAppDelegate.h #import &lt;UIKit/UIKit.h&gt; @interface iSolveMathAppDelegate : NSObject &lt;UIApplicationDelegate&gt; { UIWindow *window; UITabBarController *tabBarController; NSMutableArray *tmpArray; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) NSMutableArray *tmpArray; // variable I want to access @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; @end </code></pre> <p>iSolveMathAppDelegate.m</p> <pre><code>#import "iSolveMathAppDelegate.h" @implementation iSolveMathAppDelegate @synthesize window; @synthesize tabBarController; @synthesize tmpArray; ... - (void)dealloc { [tabBarController release]; [window release]; [tmpArray release]; [super dealloc]; } @end </code></pre> <p>The view controller class from which I want to access the tmpArray.</p> <p>referenceViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @class iSolveMathAppDelegate; @interface referenceViewController : UITableViewController { NSMutableArray *equationTypes; iSolveMathAppDelegate *data; } @property(nonatomic, retain) NSMutableArray *equationTypes; @property(nonatomic, retain) iSolveMathAppDelegate *data; @end </code></pre> <p>And finally referenceViewController.m</p> <pre><code>#import "referenceViewController.h" @implementation referenceViewController @synthesize equationTypes, data; data = (iSolveMathAppDelegate *)[[UIApplication sharedApplication] delegate]; //says that initializer element is not constant...ERROR! - (void)viewDidLoad { [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@"equationTemplates"ofType:@"plist"]; data.tmpArray = [[NSMutableArray alloc] initWithContentsOfFile:path]; self.equationTypes = data.tmpArray; [data.tmpArray release]; // obviously none of these work, as data is not set. } - (void)dealloc { [super dealloc]; [equationTypes release]; [data release]; } @end </code></pre> <p>So anyway at the line <code>data = (iSolveMathAppDelegate *)[[UIApplication sharedApplication] delegate];</code> the compiler says that the initializer element is not constant.</p> <p>I have scrouged the web for answers, and for all it seems to work...but no dice for me :( Can you please advice me on where I have gone wrong? I am using XCode 3.2 and iOS SDK 3....maybe the SDK is the problem.</p> <p>Thank You</p>
    singulars
    1. This table or related slice is empty.
    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.
    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