Question

I am using XCode 5.1.1, targeting iOS 7.0.

When creating outlets from my storyboard using the Assistant editor. I notice I have a few choices to create properties or ivars. The one I have been using is dragging directly to my *.m @implementation and it creates code like:

@implementation AudioViewController
{
    __weak IBOutlet UILabel *posLabel;
    __weak IBOutlet UILabel *durationLabel;
    __weak IBOutlet UIButton *playButton;
}

I have no need to access these outside of this class, so this seems convenient, but I am wondering if there are any "gotchas" to this method vs creating properties, especially in regards to memory management. I read on other stack answers that you must create (weak) properties or I will have to [release] manually. I am wondering if this __weak takes care of that in this context?

Thanks!

Était-ce utile?

La solution

Creating properties and instance variables with the same modifier is mostly analogous. When you are using ARC, you do not have to release strong properties or instance variables - they will be released when the object is deallocated. Interface element outlets are usually created as weak, because they are retained by the view hierarchy. You should be careful; if you intend to remove the elements from the view hierarchy at some point, you should change the modifier to strong to ensure they are retained by the view controller. Top-level outlets should also be created as strong to make sure they are retained after nib load.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top