Search code examples
iosobjective-ciphoneweak-referencesstrong-references

Which storage (weak or strong) for the elements underneath the "main" View in iOS7


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):

enter image description here

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.

enter image description here

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

  • 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.