Re: Converting a Storyboard into separate NIBs.
Re: Converting a Storyboard into separate NIBs.
- Subject: Re: Converting a Storyboard into separate NIBs.
- From: Charles Srstka <email@hidden>
- Date: Mon, 19 Jun 2017 17:37:48 -0500
> On Jun 19, 2017, at 4:29 PM, Alex Zavatone <email@hidden> wrote:
>
> From line 153 of UIViewController.h:
>
> As a convenience, the default init method will do this for you,
> and specify nil for both of this methods arguments.) In the specified NIB,
> the File's Owner proxy should
> have its class set to your view controller subclass, with the view outlet
> connected to the main view. If you
> invoke this method with a nil nib name, then this class' -loadView method
> will attempt to load a NIB whose
> name is the same as your view controller's class.
>
> The pearl is here:
>
> If you
> invoke this method with a nil nib name, then this class' -loadView method
> will attempt to load a NIB whose
> name is the same as your view controller's class.
The documentation begs to differ, though:
https://developer.apple.com/documentation/appkit/nsviewcontroller/1434405-loadview
> Prior to OS X v10.10, the loadView() method did not provide well-defined
> behavior if the nibName property’s value was nil. In macOS 10.10 and later,
> however, you get correct behavior without specifying a nib name as long as
> the nib file’s name is the same as that of the view controller. For example,
> if you have a view controller subclass called MyViewController and a nib file
> with the same name, you can employ the convenient initialization pattern
> [[MyViewController alloc] init].
The AppKit release notes agree:
https://developer.apple.com/library/content/releasenotes/AppKit/RN-AppKitOlderNotes/index.html#10_10ViewController
> loadView: would previously not have well defined behavior if there was a
> "nil" nibName. On 10.10 and later, if nibName is nil NSViewController will
> automatically try to load a nib with the same name as the classname. This
> allows a convenience of doing [[MyViewController alloc] init] (which has a
> nil nibName) and having it automatically load a nib with the name
> "MyViewController”.
The sense I get from these methods is that it might have kinda, sorta,
accidentally worked in the past, but it shouldn’t be relied on.
Reading through those release notes reminded me of *another* caveat I’d
forgotten; the functionality only correctly parses Swift class names in *10.11*
and higher. Otherwise, it’ll be looking for MyProjectName.Foo.xib instead of
Foo.xib like it should. So, if you’re using Swift, better to restrict usage of
this feature to El Cap or better.
Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden