iphone - superview and parentviewcontroller nil after adding a subview -


i think i'm missing fundamental , want ask community help. i'm building app based around basic iphone utility application. mainview , flipsideview share elements have created separate viewcontrollers , nib files pieces. in order have done following: 1. created viewcontroller called searchdateviewcontroller file's owner of searchdateview.xib 2. searchdateview.xib uiview uilabel inside, view wired correctly 3. inside both mainviewcontroller.m , flipsideviewcontroller.m add subview folllows:

- (void)loadview{     [super loadview];     searchdateviewcontroller = [[searchdateviewcontroller alloc] initwithnibname:@"searchdateview" bundle:nil];     [[searchdateviewcontroller view] setframe:[searchdateview frame]];     [[self view] addsubview:[searchdateviewcontroller view]];  ... } 

everything displays , works fine. depending on actions happen in each of main , flipside views uilabel of nib changed. however, wanted different if searchdateviewcontroller loaded mainview or flipsideview. however, can't seem figure out viewcontroller adding searchdateviewcontroller subview.

in searchdateviewcontroller tried:

- (void)viewdidload {     [super viewdidload];     nslog(@"superview %@", self.view.superview);     nslog(@"parentviewcontroller %@", self.parentviewcontroller); } 

in both cases nil.

so question - can find out viewcontroller adding searchdateviewcontroller a subview? if how? or if logic here messed up, how should doing this?

thanks!

viewdidload invoked when view controller has loaded view. in case, happends in line:

[[searchdateviewcontroller view] setframe:[searchdateview frame]]; 

at moment, haven't yet called addsubview: no wonder view's superview nil.

to solve problem, should define property inside searchdateviewcontroller distinguish between different cases. property set accordingly parent controller creates searchdateviewcontroller instance.

generally, not think idea use uiviewcontroller subclass controller view used subview of 1 or several fullscreen views rather used fullscreen view itself. of uiviewcontroller's logic works on assumption used manage fullscreen view. instance, design, think it's possible searchdateviewcontroller modify view's frame when device orientation changes etc. since don't need functionality non-fullscreen subview, suggest subclass searchdateviewcontroller directly nsobject.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -