ios - Why setNeedsDisplay required when initWithNibName used -


i have custom uiviewcontroller class called mspageviewcontroller , associated nib file. have iboutlet uiimageview called pageimage.

now, want use view controller in uiviewcontroller display series of custom mspageviewcontroller in uipageviewcontroller. so, use following code:

// alloc , init custom view controller

mspageviewcontroller *page1 = [[mspageviewcontroller alloc] initwithnibname:@"mspageviewcontroller" bundle:nil]; 

// must call or, image set below null // why? guess it's because view hasn't been drawn yet because hasn't been displayed, need force redraw - question. right approach?

[page1.view setneedsdisplay]; 

// set image

page1.pageimage.image = [uiimage imagenamed:@"tutorialpage1.png"]; 

// make array of view controllers, expects array because double-sided

nsarray *viewcontroller = [nsarray page1]; 

// pass array contains custom view controller

[self.pagecontroller setviewcontrollers:viewcontroller direction:uipageviewcontrollernavigationdirectionforward animated:no completion:nil]; 

so doing right? have force redraw outlets exist when try assign them?

as others have noted, pageimage (a uiimageview?) not loaded nib yet when you're accessing it.

if have custom getter pageimage, following:

- (uiimageview*) pageimage {     [self view];     return _pageimage; // assuming property backing ivar synthesized _pageimage. } 

but personal preference not expose imageview , expose property image. can set image viewcontroller regardless of it's loaded state, , internally set imageview once view loads:

- (void) setimage: (uiimage*) image {     _image = image;      if ( self.isviewloaded )     {          self.pageimage.image = image;     } }  - (void) viewdidload {     [super viewdidload];      self.pageimage.image = self.image; } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -