Clicky

iOS Dev Nugget 208 showViewController(_:sender:)

.

Need to run a code review on your codebase? Hire me

UIViewController adds the methods showViewController(_:sender:) and showDetailViewController(_:sender:) in iOS 8.

They do the right thing with UINavigationController and UISplitViewController, e.g for UINavigationController, showViewController(_:sender:) will push the view controller and showDetailViewController(_:sender:) will do a present it.

In your own custom view controllers, you can also override these methods to display the view controllers appropriately.

The beauty of these pair of methods is that they walk up the view controller hierarchy looking for view controllers that implement them and do the right thing.

Using showViewController(_:sender:) and showDetailViewController(_:sender:) helps decouple the shown/presented view controller from knowledge of the view controller hierarchy.


Your feedback is valuable: Do you want more nuggets like this?   Yes   or   No

.

Like this and want such iOS dev nuggets to be emailed to you, weekly?

Sign Me Up! or follow @iosdevnuggets on Twitter

.

View archives of past issues