Thursday, October 5, 2017

Understanding Outlets and Referencing Outlets sections in Interface Builder

I'm using Xcode 8 and Swift 3. I created a single view application, in which there was one table view controller (an instance of UITableViewController). Here is how it looks like in the Interface Builder.


By default, there is one outlet and two referencing outlets come with the UITableViewController such as view and dataSource and delegate, respectively. UITableViewController class inherits from UIViewController and so it inherits view property from UIViewController. The view property is of type UIView, but the table view controller initializes it with an object of UITableView named tableView. In the image above, the outlet view is connecting to Table View. Therefore, the Outlets section tells us the inner objects or the properties of the selected object (or control in Interface Builder) are assigned with what objects (or controls).

The UITableView class has dataSource and delegate properties. In Referencing Outlets section, the dataSource and delegate are referencing the Table View control. It means that the Table View, which is the inner control of the Items View Controller control, has two outlets. In other words, the tableView property of the ItemsViewController class has two properties: dataSource and delegate. However from the image above, we can't see which objects were assigned to those two properties. To see it, we have to select on the Table View control and open the Connection Inspector then look under the Outlets section. The image below shows that those two properties were referencing to Items View Controller control or ItemsViewController object.




No comments:

Post a Comment