Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

IBOutlet & IBAction question

In the beginning (let say, Chapter 3), we create IBOutlets and IBActions ctrl+dragging from UI elements onto our view controller header text. 

In later chapters (let say, Chapter 7), we code outlets and actions by hands, and then connect them in Interface Builder to File's Owner.

So, I have 2 questions:

1) Why can't we continue to create outlets and actions as we did before, just by ctrl+dragging?
2) When we code outlet manually, we use (strong, ), and when it was created for us when we ctrl+dragged, (weak, ) was used. Why do we use (strong, ) then?

Thank you!


  • If you feel more comfortable adding outlets by ctrl-dragging then you can still do that. For most of the code in chapter 7 it would work with weak as well.

    Except for what is in BIDAppDelegate.m, the reason is how ARC handles strong and weak references. An object can be released as soon as it has no strong references. That means that the tab bar controller can actually be released in between these two statements:
        [[NSBundle mainBundle] loadNibNamed:@"TabBarController" 
        self.window.rootViewController = self.rootController;
    For most outlets weak properties work because the view property on UIViewController is a strong reference, and thus it and all its subviews have at least one strong reference.

    // Fredrik
  • Thank you for your explanation! Yeah, it's just less work to ctrl+drag instead of typing :) 
Sign In or Register to comment.