Search code examples
objective-cios5global-variablesiboutlet

How do you define a global IBOutlet variable in iOS5?


The reason why I need a global IBOutlet variable is because, I don't want to lose data after you switch view back. for example, I have an IBOutlet and UIlabel and set its text.

@property (retain, nonatomic) IBOutlet UIImageView *imageView; 
@property (retain, nonatomic) IBOutlet UITextField *inputText; 
@property (retain, nonatomic) IBOutlet UILabel *warnningLabel;

After I switch back from the other view, UILabel will be set to nil, which I don't want it happen. Any ideas?


Solution

  • Try this:

    save the value using NSUserDefaults (or declare a global NSString variable) on viewDidDisappear and set UILabel.text on viewDidAppear