ios - How to recreate the UITableViewController's initializing behavior? -
i creating own base class act uitableviewcontroller replacement (let's call irtableviewcontroller). thus, subclassing uiviewcontroller , want have following initializers, in similar fashion uitableviewcontroller:
-(id)init; -(id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil; -(id)initwithstyle:(uitableviewstyle)style; the implementation above looks this:
-(id)init { return [self initwithstyle:uitableviewstyleplain]; } // designated initializer of superclass must call new designated initializer -(id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { return [self initwithstyle:uitableviewstyleplain]; } // designated initializer, must call superclass designated initializer - (id)initwithstyle:(uitableviewstyle)style { self = [super initwithnibname:nil bundle:nil]; if (self) { self.style = style; self.clearsselectiononviewwillappear = yes; } return self; } now, if do not override -loadview, things work desired when have nib file , initialize new subclass using 1 of following:
myirtableviewcontroller *vc = [[myirtableviewcontroller alloc] init]; myirtableviewcontroller *vc = [[myirtableviewcontroller alloc] initwithstyle:uitableviewstyleplain]; myirtableviewcontroller *vc = [[myirtableviewcontroller alloc] initwithnibname:nil bundle:nil]; myirtableviewcontroller *vc = [[myirtableviewcontroller alloc] initwithnibname:@"myirtableviewcontroller" bundle:nil]; the problem comes when want use base class without nib file. in case, understanding, need set view property (as add uitableview subview) in -loadview. if override method, means run in cases, when initializing objects with associated nib file.
is there way want? , worse, if override -loadview, according docs, not supposed call [super loadview], how ignore whatever happens there when have nib file?
ps. have seen matt gallagher's related post, in case calls [super loadview] , avoid that.
if have aversion calling [super loadview] in case nibname != nil load nib using loadnibnamed:(nsstring *)name owner:(id)owner options:(nsdictionary *)options ?
Comments
Post a Comment