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.
精彩评论