Because that view is already retained by the view that creates them (the one you set in the interface builder) you don't need to retain them again, so you have to choose weak, not strong.
Which storage (weak or strong) for the elements underneath the "main" View in iOS7 [duplicate]
-
19-09-2022 - |
Question
After reading really many books and docs on iOS programming I am still confused - which Storage type (weak or strong) to select, when control dragging from a UI element underneath the "main" View? (and by "main" I think I mean the UIView assigned to the view
property of the ViewController):
For example I'm trying to recreate the example iOS SDK: Working with NSUserDefaults by Mr. Jeroen van Rijn - with Xcode 5.0.2 and iOS7.
His code is lacking the weak/strong specifiers and I wonder, which would be correct here?
#import <UIKit/UIKit.h>
@interface ContactViewController : UIViewController {
IBOutlet UIImageView *contactImageView;
IBOutlet UITextField *firstNameTextField;
IBOutlet UITextField *lastNameTextField;
IBOutlet UITextField *ageTextField;
}
- (IBAction)save:(id)sender;
- (IBAction)chooseImage:(id)sender;
@end
Solution
OTHER TIPS
You don't need outlet for the view in this example. You can access it like:
self.view
in your ContactViewController or like:
ContactViewController *contact = [[ContactViewController alloc] init];
contact.view
from other view controller. However for your outlets you should you weak.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow