How iOS adds another controller to one controller

Source: Internet
Author: User

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

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.