i running interesting issue. have view controller:
loginviewcontroller *viewcontroller = [loginviewcontroller alloc] init];
in methods initwithnibname:bundle:
, awakefromnib
have initialization code. loginviewcontroller has .xib file named loginviewcontroller.xib.
however, building against ios 9, methods never called , code never run. unless however, initialize loginviewcontroller
this:
loginviewcontroller *viewcontroller = [loginviewcontroller alloc] initwithnibname:nil bundle:nil];
then code run , works fine. appears .xib file being loaded, initwithnibname:bundle:
, awakefromnib
never called.
does know why in ios 9 awakefromnib
isn't getting called default when corresponding .xib exists? issue did not exist in ios 8 (awakefromnib
called if used init
initialize view controller).
changes view controller nib loading behavior described in ios 9 release notes:
if initialized nil nibname value, uiviewcontroller.nibname has looked nib similar name view controller’s class, , defaulted value if loadview not overridden. prior ios 9, subclasses of uiviewcontroller written in swift require corresponding nib file name include module prefix.
to improve flexibility in event of refactoring, can omit module name nib filename in code runs in ios 9. uiviewcontroller.nibname still prefers name contains module prefix, falls unqualified name if nib fully-qualified name not found.
additionally, class documentation uiviewcontroller states:
if specify nil nibname parameter , not override loadview method, view controller searches nib file described in nibname property.
if performing initialization in -initwithnibnamed:bundle:
preferable instead in -initwithcoder:
and/or -loadview
(depending on doing). -awakefromnib
still appropriate things should go there.
from question seems that: - -initwithnibnamed:bundle:
, awakefromnib
not being invoked when view controller subclass instantiated -init
. - -initwithnibnamed:bundle:
, awakefromnib
are being invoked when view controller subclass instantiated -initwithnibnamed:bundle:
.
this little curious. -initwithnibnamed:bundle:
designated initializer , -init
should calling nil arguments trigger behavior described above. quick disassembly of uikit on ios 9 hopper shows still case.
if override -loadview
-initwithnibname:bundle:
not attempt load nib - overriding -loadview
opting doing yourself. if overriding -loadview
(even if call super), remove , nib should load. -awakefromnib
won't called because view controller nib's owner - children method call. if part of storyboard called. -awakeafterusingcoder:
, however, called , may better place work attempting in -awakefromnib
.
i reduced question simple test case , confirmed behavior on ios 9 , ios 8.4 sdks.
Comments
Post a Comment