官术网_书友最值得收藏!

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:

  1. 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.
  2. Open the Main.storyboard. We will click on View Controller Scene in the left pane of our storyboard file and delete it:
  1. 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:
  1. 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:
  1. 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 Controllerthen 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:
  1. 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:

主站蜘蛛池模板: 丹棱县| 哈尔滨市| 来安县| 双峰县| 和平县| 象山县| 黄骅市| 西充县| 大田县| 太原市| 广安市| 彩票| 赣州市| 勃利县| 凌云县| 阿拉善左旗| 库伦旗| 桃江县| 屏东县| 新蔡县| 罗田县| 湾仔区| 四子王旗| 凌云县| 奉节县| 扶风县| 仙居县| 大悟县| 惠州市| 宜州市| 黄平县| 内丘县| 新沂市| 衡南县| 固镇县| 堆龙德庆县| 石河子市| 疏附县| 大渡口区| 乐至县| 儋州市|