[iOS notes]-Addchildviewcontroller
Multiple sub view can be added to the view controller, which is displayed when needed;
Multiple child viewcontroller can be added through Viewcontroller (parent) to control Sub view in the page, reducing the coupling of the Code;
By toggling, you can display different view, and replace the management of the previous Addsubview
//Add a child view controller to the parent view ControllerFirstviewcontroller *firstviewcontroller=[[firstviewcontroller Alloc] Initwithnibname:@"Firstviewcontroller"Bundle:nil]; [Self addchildviewcontroller:firstviewcontroller]; Secondviewcontroller*secondviewcontroller=[[secondviewcontroller Alloc] Initwithnibname:@"Secondviewcontroller"Bundle:nil]; [Self addchildviewcontroller:secondviewcontroller]; Thirdviewcontroller*thirdviewcontroller=[[thirdviewcontroller Alloc] Initwithnibname:@"Thirdviewcontroller"Bundle:nil]; [Self addchildviewcontroller:thirdviewcontroller]; [Self.view AddSubview:thirdViewController.view]; //Addchildviewcontroller calls back [child willmovetoparentviewcontroller:self], but does not call Didmovetoparentviewcontroller, So you need to show the call[Thirdviewcontroller didmovetoparentviewcontroller:self]; Currentviewcontroller=Thirdviewcontroller; //Switch Child View Controller[Self transitionfromviewcontroller:currentviewcontroller toviewcontroller:firstviewcontroller Duration:4Options:uiviewanimationoptiontransitionflipfromleft animations:^{} completion:^(BOOL finished) {//...... }]; Currentviewcontroller=Firstviewcontroller; //Remove Child View Controller//Removefromparentviewcontroller does not call [self willmovetoparentviewcontroller:nil] until the child is removed, so it is necessary to display the call[Currentviewcontroller Willmovetoparentviewcontroller:nil]; [Currentviewcontroller Removefromsuperview]; [Currentviewcontroller Removefromparentviewcontroller];
Addchildviewcontroller New Method 5.0