uiview - iOS - Why setting and displaying subviews in initWithNibName doesn't work? -
uiview - iOS - Why setting and displaying subviews in initWithNibName doesn't work? -
i have simple xib file layout is:
which pale greenish uiview referenced iboutlet view_content
in uiviewcontroller class. did next in initwithnibname:bundle:
of viewcontroller.m:
self = [super initwithnibname:nibnameornil bundle:nil]; if (self) { self.view_a = [[uiview alloc] initwithframe:cgrectmake(100, 100, 100, 100)]; self.view_a.backgroundcolor = [uicolor purplecolor]; [self.view_content addsubview:self.view_a]; self.view_b = [[uiview alloc] initwithframe:cgrectmake(150, 150, 100, 100)]; self.view_b.backgroundcolor = [uicolor bluecolor]; [self.view_content addsubview:self.view_b]; self.view_c = [[uiview alloc] initwithframe:cgrectmake(200, 200, 100, 100)]; self.view_c.backgroundcolor = [uicolor greencolor]; [self.view_content addsubview:self.view_c]; } homecoming self;
i expected there 3 little squares, each different colors declared in code above, did not show view loaded , showed. instead if move addsubview:
calls viewdidload
, displayed expected. tried test if view_content
nil in if-segment , seems nil @ time. don't understands why happening , how works, isn't view , components supposed loaded xib?
thanks help!
at point initwithnibname:...
called, view not yet loaded. optimization (lazy loading) defers loading view until needed. view loaded when viewcontroller.view
first-time accessed, , that's when viewdidload
called.
some people forcefulness view controler load view calling [viewcontroller view]
(or [self view]
if it's within view controller's class).
ios uiview interface-builder xib
Comments
Post a Comment