![]() ![]() Now that we know why we need a navigation view controller, let's add it to our storyboard. This navigation pattern provided by the UINavigationViewController is also incorporated in Apple's Mail and Messages app. The navigation controller will create a back button in the top bar that can be used to easily navigate back to the list view. When we select an entry in the List View Controller we want to push our Detail View Controller for that entry. A UINavigationViewController maintains a stack of view Controllers. For the type of app we are creating now an UINavigationViewController is ideal. Whenever an app has more than one view controller that we want to display, we need to use container view controllers that can handle multiple child view controllers and provide easy mechanics for users to switch between them. To complete the basic layout of our app we need to add a way to switch between the list and the detail view. For now we will just configure the high level navigation in our app, that means we won't fill the Detail View Controller with views just now. This blank view controller will become our Detail View Controller. Select a View Controller from the Object Library in the bottom right and drag it to the storyboard. For this second view controller we will not use a template but instead start with a blank view controller. Now we'll add the view controller that will display the details of a selected Note. If you are working on a Mac with a small screen you might want to downscale the iOS Simulator: The iPhone 6 and the iPhone 6 Plus Simulators have large screen sizes. Now that we have configured a root view controller we can run the app for the first time and we should be able to see an empty list: The initial view controller within the main storyboard file is the one that will be displayed as root view controller. In storyboard based applications the ist file has an entry Main storyboard file base name that indicates the main storyboard file. The easiest way to ensure that the controller is selected is using the Document Outline in the left panel. Make sure you have selected the table view controller and not the table view, otherwise you won't be able to find the setting in the inspector. Check the box for is initial View Controller: In Interface Builder we can configure this by selecting the table view controller and opening the Attributes Inspector in the right panel. IOS needs to know which view controller in our app should be displayed first (this view controller is called the root view controller). Now you have added the first view controller to your app. ![]() You can use the search bar at the bottom to filter the list:ĭrag the selected controller to the storyboard stage. Now select the Table View Controller from the Object Library on the bottom right of the Interface Builder UI. Now your Xcode project should look like this: Remove the ViewController.swift class from Xcode (Select "Move to Trash" when prompt appears).Select the view controller in the Storyboard by clicking into it and hit the delete key.Before we create it let's remove the default view controller that has been created as part of the template: Since that component is used very often Interface Builder provides a template view controller called Table View Controller that provides a basic table view and a ViewController that is associated with it. Whenever we want to display items in a list on iOS we use a component called UITableView. Let's start by creating the first view controller that displays a list of notes. #Setting up the Notes List View Controller ![]() Open the Main.storyboard file to get started. We will design the entire layout of this app in storyboard. The app will consist of two different view controllers, the first one will display a list of notes, the second one will display the details of a note when it is selected from the list. We want to create an app that can display notes. You will see that the template contains, among additional files, an AppDelegate class, a ViewController class and a Main.storyboard file: Then choose create a Single View Application:Ĭhoose the name for your application and select Swift as language:Īfter hitting next and choosing a project location Xcode will create the new project, based on a project template. Open Xcode 6.1 (6A1052d) and select File -> New Project. There may be errors in other versions of Xcode. This code was last tested on Xcode 6.1.1 (6A2008a). There is an Objective-C version of this tutorial located here. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |