Practice English Speaking&Listening with: 多个视图

Difficulty: 0

Congratulations, you've made it through the first hurdle in iOS development.

You have UI elements, and

you've wired them up to call your code with IB actions.

And you've reach back to the UI using IB outlets.

In the second part of this lesson, you're going to learn how to set up

multiple views, so that you can go between two different view controllers.

No more single view applications for you.

Most iOS applications you will be developing will venture

further than a single screen.

In order to use multiple view controllers,

you will need another class, that let's you navigate between them.

There are two common classes to use for

handling multiple view controllers in iOS.

UI navigation controller and, UI tab are controller.

Both of these are covered in depth when you get to UI kit fundamentals

in the next module.

For now let's just discuss the basics of a UINavigation Navigation controller.

The UINavigation Controller is a class that handles a stack

of multiple view controllers.

Like any other stack in computer science or real life, you can insert and

remove items from the stack.

In the UINavigation Controller you start out with a single view controller,

called the rootViewController.

You can add as many of your controllers on top of it as you'd like.

In pitch perfect we're going to have just two view controllers.

One for recording, and one for playback.

So our use UINavigationController, will be just for those two screens.

Before we can run, we need to walk.

Currently our app have the view controller named ViewController

as a start of the app.

With the main story board opened selected.

Notice the little gray arrow here that indicates that

this is the initial view controller.

If you have multiple view controllers, you can drag this arrow to change

which view controller to storyboard, and therefore your app, will start with.

This arrow is also driven by the checkbox

titled is initial view controller here in the attribute inspector.

If you uncheck this arrow, the storyboard won't know

what view controller to start the app with and you'll get a runtime crash.

Make sure the is initial view controller is checked.

With the view controller selected, the orange circle here in the document

outline, go into the editor menu and select embed in navigation controller.

You can see that x code has created a UInavigation controller

to start the app, and that our view controller is the root view controller

of that navigation controller.

Now you're ready to add more view controllers to pitch perfect.

The Description of 多个视图