Prior to the use of TableView encountered problems, you need to use another tableviewcontroller to store TableView, the original view uses Viewcontainer to refer to Tableviewcontroller. This is the first time to contact a viewcontroller using another viewcontroller. Later encountered in the development of other problems also need to use Childviewcontroller, originally this kind of problem can use custom view to solve. When developing Android, the custom view can specify a layout file, but iOS cannot assign a layout file to a custom view, and it is difficult to implement control layout by code, so search for viewcontainer related issues.
Using Viewcontainer is also a viewcontroller that adds a child to the Viewcontroller. In the visual storyboard can use Viewcontainer, but with pure code control, or with Childviewcontroller more convenient.
Childviewcontroller is iOS5 out of the new things, iOS5 to Uiviewcontroller added 5 methods and a property, around this Childviewcontroller
// Method AddChildViewController:removeFromParentViewController:transitionFromViewController:toViewController: Duration:options:animations:completion:willMoveToParentViewController:didMoveToParentViewController:/ / attribute @property (nonatomic,readonly) Nsarray *childviewcontrollers
In my opinion, the above method attributes can be words too literally, the function of the method is to add Childviewcontroller, remove childviewcontroller, switch Childviewcontroller, the following two methods are event nature, Triggered after the Childviewcontroller switches to the master's Viewcontroller and after switching.
But my current application scenario is the need to put Childview into the scrollview inside, to achieve the effect of page flipping.
Two viewcontroller were added to the storyboard, one was the Uiscrollview added to the main and added as Childviewcontroller to the Parentviewcontroller.
First add the Childview Stroyboard in the name, then in the main Viewcontroller structure Viewcontroller can be constructed according to Storyboardid.
Since the Uiscrollview implements the paging function, it should be configured as follows
Self.scrollview.contentsize=cgsizemake (self.view.frame.size.width*PageCount, self.scrollView.frame.size.height); self.scrollView.pagingEnabled=true;
The code to add Childviewcontroller is shown below
Sunrealaqiviewcontroller *realcv2=[[self storyboard]instantiateviewcontrollerwithidentifier:@ " test123"];realcv2.view.frame0, Self.view.frame.size.width, Self.view.frame.size.height); [Self addchildviewcontroller:realcv2]; [Self.scrollview AddSubview:realCV2.view];
First constructs the Childviewcontroller, and then sets its Frame property, at this time the page, the first page may not set, but the second page third page needs to go to set up, The third line is to call Uiviewcontroller's Addchildviewcontroller method to add the Childviewcontroller inside, and finally to add the Childview view to the location specified Here is to add to scrollView inside go, so is called [Self.scrollview Addsubver:] method, need to add multiple same childviewcontroller to scrollView inside must use loop
for (int i=0; i<pagecount; i++) { *realcv2=[[self Storyboard] Instantiateviewcontrollerwithidentifier:@ "test123"]; RealCV2.view.frame0, self.view.frame.size.width, self.view.frame.size.height); [Self addchildviewcontroller:realcv2]; [Self.scrollview AddSubview:realCV2.view];}
This is the way to open the door to use Childviewcontroller!
iOS Learning notes-using Childviewcontroller