开发者

iPhone Dev - Storing and Retrieving Variables from App Delegate

开发者 https://www.devze.com 2022-12-09 18:10 出处:网络
I have created a variable in my App Delegate and from my first View Controller, I am saving a value to the variable (in the App Delegate).

I have created a variable in my App Delegate and from my first View Controller, I am saving a value to the variable (in the App Delegate).

Here is how I'm saving the value to the variable in the App Delegate:

MyAppDelegate *DelegateVar = TheValue;

NSLog(@"%@", DelegateVar); // This NSLog outputs correct value

Later in the program, in a separate ViewController, I am trying to retrieve the value from the App Delega开发者_运维问答te. I am getting values that look to be pointers...

Here is how I'm trying to retrieve the value:

MyAppDelegate *MyVar = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

NSLog(@"%@", MyVar); // outputs incorrect value

Anybody that has any input regarding my problem, your help would be greatly appreciated.


This doesn't make sense. Why are you assigning a value to a pointer to your application's delegate in the first place? If you want to assign a value to an instance variable inside your delegate, then you need to do something completely different.


First, you should check the main XIB file to ensure the delegate is wired up to the application.

Second, try replacing TheValue in the first instance with [[UIApplication sharedApplication]delegate] and see if you get the same incorrect value as you do later on.

0

精彩评论

暂无评论...
验证码 换一张
取 消