UIViewController dismissViewControllerAnimated:completion:.


#1

On page 333 of the book, there is a little blurb about having to call dismissViewControllerAnimated:completion: on the BNRItemsViewController that is presenting the BNRDetailViewController. However, in the iOS documentation, it sates that:

So, this means the line to be added could be:

[self dismissViewControllerAnimated:YES completion:nil];

I wonder if this has changed recently or if the authors just wanted to be very explicit.


#2

We wanted to be very explicit. The code that you mentioned would indeed work in the situation presented in the book, but let’s throw out a hypothetical example (that is not all that uncommon in the real world).

Say the BNRDetailViewController presents a view controller itself. We’ll call that BNREditImageViewController. So we have a hierarchy like: BNRItemViewController -> BNRDetailViewController -> BNREditImageViewController.

If we then call [self dismissViewControllerAnimated:YES completion:nil]; from the BNRDetailViewController, then just the BNREditImageViewController would be dismissed, and we’d be left at the BNRDetailViewController. If we instead did [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];, then both the BNRDetailViewController and the BNREditImageViewController would be dismissed, and we’d (correctly) be left at the BNRItemViewController.


#3

Great. Thanks for clearing that up.