ios - Why some Outlets are made strong references even tough the documentation specifies that outlets should be weak reference -


Hello I'm a newbie for iOS programming. I know what a strong and weak reference is but I am confused that when I have to deal with the outlet, then what kind of reference is to use. After going through the documents, which states that

Shops should generally be vulnerable, except in a nib file (or, in iOS, storyboard view) by the owner of the file. Except top-level objects should be strong.

So after going through the above statement, what has been explained to me that the outlets we make are usually weak by default

But while studying some tutorials, I have come across the code where people have declared an outlet as a strong reference for example, consider the following code:

  @interface AboutViewController: UIViewController @property (nonatomic, strong) IBOutlet UIWebView * webView; @end  

Code:

  @property (nonatomic, strong) IBOutlet UIWebView * webView;  

says that there is a UIWebView object in our VCI controller about

but for us the UIView object here Why is strong context required? ?? Documents should not be a weak reference in the form of states?

Also explain in the documentation description, which I have cited above, what does file owner top-level objects mean ?.

There are many such questions on this website but none of them helps to clear my doubts. Please help please in advance :)

What to use for non-top level GUI elements - strong Or weak - depending on how you will use your outlet if you have a weak reference

  @property (nonatomic, weak) IBOutlet UIWebView * webView;  

Then after calling method

  [webView removeFromSupeview];  

Your webview will be empty and it will be impossible to restore the UIView by simply adding it

  [self.view addSubview: webView];  

If this is suitable for you - it is better to use weak because you can not make the webview storage free when you do not need it.

On the other hand, after strong context

  [webView removeFromSupeview];  

There will still be references in the webview> 0 and the webview will only be removed if the owner clears it clearly

  self.webView = zero ;  

or owner of

  - (zero) dealloc  

together with the owner.

There is usually no difference if you have a static GUI If you want to remove (hide) to be able to add some scenes later, strong references should be used. .

The top-level object should be kept strong like

  @property (nonatomatic, retaining) UIView * view; In the  

UIViewController


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -