Note that there are some explanatory texts on larger screens.

plurals
  1. POBest practices for handling changes to the UINavigationItem of child view controllers in a container controller?
    primarykey
    data
    text
    <p>Suppose I have a container controller that accepts an array of UIViewControllers and lays them out so the user can swipe left and right to transition between them. This container controller is wrapped inside a navigation controller and is made the root view controller of the application's main window.</p> <p>Each child controller makes a request to the API and loads a list of items that are displayed in a table view. Based on the items that are displayed a button may be added to the navigation bar that allows the user to act on all the items in the table view.</p> <p>Because UINavigationController only uses the UINavigationItems of its child view controllers, the container controller needs to update its UINavigationItem to be in sync with the UINavigationItem of its children.</p> <p>There appear to be two scenarios that the container controller needs to handle:</p> <ol> <li>The selected view controller of the container controller changes and therefore the UINavigationItem of the container controller should update itself to mimic the UINavigationItem of the selected view controller.</li> <li>A child controller updates its UINavigationItem and the container controller must be made aware of the change and update its UINavigationItem to match.</li> </ol> <p>The best solutions I've come up with are:</p> <ol> <li>In the setSelectedViewController: method query the navigation item of the selected view controller and update the leftBarButtonItems, rightBarButtonItems and title properties of the container controller's UINavigationItem to be the same as the selected view controller's UINavigationItem.</li> <li>In the setSelectedViewController method KVO onto the leftBarButtonItems, rightBarButtonItems and title property of the selected view controller's UINavigationItem and whenever one of those properties changes up the container controller's UINavigationItem.</li> </ol> <p>This is a recurring problem with many of the container controllers that I have written and I can't seem to find any documented solutions to these problems.</p> <p>What are some solutions people have found to this problem?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload