ios - view controller initilization -
usually view controller initialized in application delegate this:
- (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { self.window = [[uiwindow alloc] initwithframe:[[uiscreen mainscreen] bounds]]; // override point customization after application launch testviewcontroller *vc = [[testviewcontroller alloc] **init**]; self.window.rootviewcontroller = vc; return yes; } but vc implement initialization method - (instancetype)initwithnibname:.
how init call initwithnibname:? call sequence?
if @ default implementation, calls superclass's version:
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { // custom initialization } return self; } implementing initwithnibname not required, since default init method call super implementation of initwithnibname:nibnameornil you.
if creating testviewcontroller using code (no xibs), code posted acceptable. otherwise, should call initwithnibname , pass name of nib used view controller.
Comments
Post a Comment