Re: Converting a Storyboard into separate NIBs.
Re: Converting a Storyboard into separate NIBs.
- Subject: Re: Converting a Storyboard into separate NIBs.
- From: Alex Zavatone <email@hidden>
- Date: Mon, 19 Jun 2017 17:52:17 -0500
I think we’re reading this differently. But I remembered reading the header
info from Mac OS in 2009, which I’ll have to look into.
What I pasted from line 153 of UIKit, UIViewController.h, (NOT AppKit
NSViewController.h) explicitly says that “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."
I don’t know how much clearer it can get. Buuuuuuut to support your point…
You and I are both pasting from the docs, but we’re probably pasting past each
other with one on iOS and one on Mac OS. In any case, we can’t see under the
hood of UIKit or AppKit.
I’m installing a VM now, so if time permits, it will be interesting to see how
this fails, back to Xcode 3.x on Mac OS and iOS.
There are two things that I am aware of. 1, on iOS, I’ve never had a problem
here. 2, never ignore it when the docs say that “this could be trouble.”
Thanks Charles. This has certainly been interesting. I appreciate the time
you put in to show exactly where this could be an issue.
- Alex Zavatone
> On Jun 19, 2017, at 5:37 PM, Charles Srstka <email@hidden> wrote:
>
>> 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