Hi I’ve seen an answer to this question:
How to pass a value from one view to another view
And I’m having some trouble. I’ve stored a string in the header file of the AppDelegate.
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
NSString *commString;
}
@property (strong, nonatomic) UIWindow *window;
@end
I now need to access this and change it in one view. Then display it in another view. The answer on the previous page explains this briefly, but I’m having trouble with the second part of the answer. It wont let me do:
AppDelegate.commString = myString; //mystring being an NSString
Any ideas please?
Thanks
The problem is twofold. First, that you are trying to access an ivar on a class, and second that it is a class instead of an instance.
[[UIApplication sharedApplication] delegate];returns a valid instance of the delegate class as a singleton for easy access in multiple locations, but you need to declare the ivar as an @property, or else risk using the (extremely unstable) struct access operator.