Recent projects require multiple view issues for adding another controller on the current controller due to project needs. Make a note here, for convenience, the current view controller is recorded as Controller 1, the added view is recorded as Controller 2
First case:
1. First, because there is a need to interact with the user on the view of controller 2, be sure to set the sub-controller of 2 1
Viewcontroller *VC2 = [[Viewcontroller alloc]init];
[Self ADDCHILDVIEWCONTROLLER:VC2];
PS: May also be used when there are multiple sub-views, the Removefromparentviewcontroller method of the child controller
2. About the creation of 2 view
Since the creation of the view involves a 2 Viewdidload method, the VC2 view is not recreated in the Controller 1 method, or another object is created. Here, you just need to design the frame of the VC2 view as needed. As follows:
Vc2.view.frame = CGRectMake (0, 108, kscreenwidth, kScreenHeight-108);
Second case:
- We create a Zytestviewcontroller:uitableviewcontroller
Then we slightly implement the following TableView data source method
Just don't make it so complicated. First, this completes the creation of a Uitableviewcontroller
- Next we add the view of this controller to our master control (Uiviewcontroller)
Then let's see if we have the effect we want:
We can actually add this tableview, but there's a problem that doesn't show the data.
- The reason: Our Zytestviewcontroller controller is dead because it is a local variable, so our data cannot be displayed. The view that caused a control is still there, but the view controller is dead, this very dangerous thing.
- So we need to keep the controller, so we need to make a strong reference to the controller.
Let's look at the effect again:
That's the only way to show our cell data.
So a conclusion: as long as the view is in, the controller of the view must be in order to ensure that the data and business logic inside the view is normal.
How iOS adds another controller to one controller