![]() ![]() ![]() Next, the items in the storyboard need to be configured to be instances of these subclasses. ![]() Select a location into which to generate the new class files and click on Create. On the following screen, name the new class AttractionTableViewCell, change the Subclass of menu to UITableViewCell and proceed with the class creation. Within the new file dialog, select Cocoa Touch Class and click Next. Perform this step by selecting the File -> New -> File… menu option. To extend this class, it is necessary to, once again, create a subclass. Later in this chapter, we will add a label and an image view object to this cell. Within the Table View Controller added to the storyboard in the previous section, Xcode also added a prototype table cell. Select a location into which to generate the new class files before clicking the Create button. Ensure that the Also create XIB file option is turned off and click Next. Click Next and on the subsequent screen, name the class AttractionTableViewController and change the Subclass of menu to UITableViewController. To achieve this, select the File -> New -> File… menu option, and in the resulting panel, select the option to create a new iOS Source Cocoa Touch class. Currently, this subclass does not exist within our project, so we need to create it before proceeding. We will declare the Table View Controller instance within our storyboard as being a subclass of UITableViewController named AttractionTableViewController. Creating the UITableViewController and UITableViewCell Subclasses Before doing so, however, we need to create those subclasses. So that we can extend the functionality of these instances, we need to declare them as subclasses of UITableViewController and UITableViewCell, respectively. At the moment, these are generic UITableViewCell and UITableViewController classes that do not give us much in the way of control within our app code. Within this instance is a prototype table view cell that we can configure to design the cells for our table. Within the storyboard, we now have a table view controller instance. Display the Library panel, drag a Table View Controller object, and drop it onto the storyboard canvas as illustrated in Figure 28-1: Select the Main.storyboard file so that the canvas appears in the center of the Xcode window. As such, we will need to add a Table View Controller instance to the storyboard file. Adding the TableView Controller to the Storyboardįrom the user’s perspective, the entry point into this app will be a table view containing a list of tourist attractions, with each table view cell containing the attraction’s name and corresponding image. We are ready to build a storyboard-based app using the UITableView and UITableViewCell classes. The full book contains 93 chapters and 760 pages of in-depth information.Īt this point, we have a template project consisting solely of a storyboard file and the standard app delegate code file. You are reading a sample chapter from iOS 16 App Development Essentials.īuy the full book now in eBook or Print format. Finally, select the option to move the file to the trash in the resulting panel. Next, select and delete the corresponding ViewController.swift file from the project navigator panel. Within the storyboard canvas, select the View Controller scene to highlight it in blue, and press the Delete key on the keyboard. To fully understand how to create a Storyboard-based TableView app, we will start with a clean slate by removing the view controller added for us by Xcode. In addition, this view controller is represented within the Storyboard file, the content of which may be viewed by selecting the Main.storyboard file. Start Xcode and create an iOS App project named TableViewStory with the Swift programming language option selected.Ī review of the files in the project navigator panel will reveal that, as requested, Xcode has created a view controller subclass for us named ViewController. Once this topic has been covered, the next chapter (entitled Implementing iOS 16 TableView Navigation using Storyboards) will explore the implementation of table view navigation and data passing between scenes using storyboards. This chapter aims to work through a detailed example to demonstrate dynamic table view creation within a storyboard using table view prototype cells. Before the introduction of Storyboards, this would have involved considerable coding work combined with trial and error. Prototype cells allow the developer to visually design the user interface elements that will appear in a table cell (such as labels, images, etc.) and then replicate that prototype cell on demand within the table view of the running app. One of the most powerful features of Xcode storyboards is the implementation of table views through prototype table cells.
0 Comments
Leave a Reply. |