Xcode4.3 implement multi-view Conversion

Source: Internet
Author: User

Recently, I found that the example is a little old and xcode has changed. So I wrote a post about view switching and provided a reference for myself.

Let's get started!

Implementation:

Here we implement switching between two views.

1. We need two views (XIB file-firstview. XIB secondview. XIB)

2. We need three view control classes: firstviewcontroller, secondviewcontroller, and switchviewcontroller.

Why do we need three view control classes?

Firstview -- firstviewcontroller

Secondview -- secondviewcontroller

Switchviewcontroller -- convert -- [firstview <-> sencondview]

Code Implementation:

I.Build a project---

1. Open xcode file --> New... --> project -->

SelectEmpty Application (xcode 3YesWindow-base Application ).

Click Next to name the project changeviewtest.

Do not select the three.

Here,Our project has been initially set up..

----------II.Create view and View class--------

1. Under the project package, right-click --- New File --- and select user interface on the left.

Select View

2. Next step,InDevice FamilySelectIphone

3. Next, name it firstview.

The generated firstview. XIB is the corresponding file.

Next we will use the same method to create secondview. XIB;

4. Add controls in * view. XIB. Here I will add a button and label control for the two views respectively ..

5. Now, we create firstviewcontroller and secondviewcontroller for firstview. XIB and secondview. XIB respectively.

6. Create the firstviewcontroller class to inherit from uiviewcontroller.

The secondviewcontroller class is created and inherited from uiviewcontroller.

7. After creation:

8. Associate the view with the view class.

[FirstView-FirstViewController]

9. Associate the view with the view class.

Select firstview. XIB, select File's owner, and write the custom class as firstviewcontroller In the attribute selector .:

10. Associate the view of the current view with outlets.

Left-click View to draw a line

After that, we joined the view and View class.

11. Add a class to control viewcontroller: switchviewcontroller

In the control classSwitchViewControllerAdd code to implement2Views.

Description:InitViewMethod used for initialization during program loadingView,ShowFirstViewMethod to display the firstView,ShowSecondViewUsed to display secondView

Connect:

---------3..Delegate,ActivateSwitchviewcontrollerControl Functions--------

1. Select appdelegate. H. Add the following code:

2.NextAppdelegate. mImplementation:

+ (Appdelegate *) app {

Return (appdelegate *) [[uiapplication sharedapplication] Delegate];

}

3.SetSwicthviewncontrollerSetWindowOfRootviewcontroller,Operation View.

-----Last,ImplementationFirstviewcontrollerAndSecondviewcontrollerView switching----

1.InFirstviewcontrollerAddIbaction,Implement button Switching,As follows::

-(Ibaction) buttonclick: (ID) sender {

[[Appdelegate app]. switchviewcontroller showsecondview];

}

2.InSecondViewControllerAddIBAction,Implement button Switching,As follows::

(If you want to import appdelegate to the project)

Last:Run the program:

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.