Navigating with UINavigationController

With the application still running, create a new item and select that row from the UITableView. Not only are you taken to DetailViewController’s view, but you also get a free animation and a Back button in the UINavigationBar. Tap this button to get back to ItemsViewController.

Notice that you did not have to change the show segue that you created in Chapter 13 to get this behavior. As mentioned in that chapter, the show segue presents the destination view controller in a way that makes sense given the surrounding context. When a show segue is triggered from a view controller embedded within a navigation controller, the destination view controller is pushed onto the navigation controller’s view controller stack.

Because the UINavigationController’s stack is an array, it will take ownership of any view controller added to it. Thus, the DetailViewController is owned only by the UINavigationController after the segue finishes. When the stack is popped, the DetailViewController is destroyed. The next time a row is tapped, a new instance of DetailViewController is created.

Having a view controller push the next view controller is a common pattern. The root view controller typically creates the next view controller, and the next view controller creates the one after that, and so on. Some applications may have view controllers that can push different view controllers depending on user input. For example, the Photos app pushes a video view controller or an image view controller onto the navigation stack depending on what type of media is selected.

Notice that the detail view for an item contains the information for the selected Item. However, while you can edit this data, the UITableView will not reflect those changes when you return to it. To fix this problem, you need to implement code to update the properties of the Item being edited. In the next section, you will see when to do this.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset