上QQ阅读APP看书,第一时间看更新
Wiring up the view
Storyboard is where you define the flow of your application. It's where the initial View Controller is defined and also the place where you can set up other View Controllers and connect them. Configuring our app's UI is done using Xcode, but all of these configurations can be programmatically done by writing additional code.
To use our new TableViewController file in our application, we need to edit our main storyboard. To do so, we need to perform the following steps:
- Delete the ViewController.swift file in our project as we will not be using it. You can do so by right-clicking on the file, selecting Delete, and then in the modal selecting Move to Trash.
- Open the Main.storyboard. We will click on View Controller Scene in the left pane of our storyboard file and delete it:
- Drag the Navigation Controller from the Object Library on the bottom right-hand corner of Xcode. You can filter for it by typing Navigation Controller in the filter field. Navigation Controller comes with a Table View Controller when you drag it into the storyboard and it will be set as the Root View Controller:
- Click on the Root View Controller and then go to the Identify Inspector which is on the top right corner of Xcode. In Class field, type ItemTableViewController, our newly created controller:
- Tell storyboard that the Navigation Controller is our Initial View Controller and to start the app from there. We can do so by first selecting Navigation Controller, then selecting the Attributes Inspector tab in the top-right corner and checking the Is Initial View Controller checkbox. As a confirmation, we will not see an arrow to the left of our Navigation Controller in the storyboard:
- Run the app by clicking on the play button on the top-left corner of Xcode to make sure we have wired everything correctly and the app runs:
The app will not do anything exciting, but in the next section we will write code in our Table View Controller to start creating, editing, and deleting our Shopping List Items: