Addchildviewcontroller New Method 5.0

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.