objective c - Creating multiple subviews inside view controller -


i have view controller named viewcontroller.

  • viewcontroller displays uiview has button on it, allows me advance second view controller - secondviewcontroller.
  • secondviewcontroller has button on it, allows me advance third view controller.

however, having trouble displaying thirdviewcontroller. when tap button in secondviewcontroller throws error:

warning: attempt present ... on ... view not in window hierarchy!

i have been bunch of other sites , posts address issue, cannot seem find working solution. have implemented quite few solutions, none seem work.

here code:

- (void)secondaryview:(uiview *)secondaryview {     uiview *theview = secondaryview;      uiviewcontroller *viewcontroller = [[uiviewcontroller alloc] init];     viewcontroller.view.frame = [uiscreen mainscreen].bounds;      [viewcontroller.view addsubview:theview];     viewcontroller.modaltransitionstyle = uimodaltransitionstylecrossdissolve;     [self presentviewcontroller:viewcontroller animated:yes completion:nil]; } 

secondaryview uiview constructing elsewhere in application. add viewcontroller present viewcontroller.

is there way dynamically create uiviewcontrollers, add uiview each one, , add them window hierarchy?

if can use navigation in viewcontrollers, can try below code

in place call firstviewcontroller,

   -(void)callfirst     {     firstviewcontroller *first = [firstviewcontroller alloc] init];     uinavigationcontroller *navigationcontroller = [uinavigationcontroller alloc] initwithrootviewcontroller:first];     navigationcontroller.modalpresentaionstyle = uimodalpresenationformsheet;     [self presentmodalviewcontroller:navigationcontroller animated:yes]; } 

and in firstviewcontroller button action ,you can write

-(void)callsec { secondviewcontroller *sec = [secondviewcontroller alloc] init]; [self.navigationcontroller pushviewcontroller:sec animated:yes]; } 

and in secondviewcontroller can same

  -(void)callthird     {         thirdviewcontroller *third = [thirdviewcontroller alloc] init];         [self.navigationcontroller pushviewcontroller:third animated:yes];      } 

try this...and in these viewcontrollers can whatever coding want meet requirement like

-(void)viewdidload { uiview *newview = [[uiview alloc] initwithframe:cgrectmake(20,20,400,400)]; newview.backgroundcolor = [uicolor redcolor]; [self.view addsubview:newview]; } 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -