metova / ThunderCats

ThunderCats is a lightweight collection of utility extensions added to existing Foundation & UIKit classes.
https://metova.com
MIT License
19 stars 4 forks source link

UINavigationController Blocks #5

Closed kylebshr closed 9 years ago

kylebshr commented 9 years ago

Add categories on UINavigationController for pushing and popping with completion blocks. This includes basic tests. OCMock has also been added to the Podfile.

bsmith11 commented 9 years ago

Whats the use case for this?

kylebshr commented 9 years ago

It's often useful to run code after the animation for pushing or popping a view controller. One such use case is the need to update the UI of the previous view controller on the stack after pushing a view controller. Rather than placing that code in the pushed view controller, where it really doesn't belong, you can place it in the completion block of tc_pushViewController. Then the UI will be updated after the push, and your code is still very organized.

One might say that viewDidDisappear can be used for this purpose, but that also gets called when the view is popped, dismissed, presents a view controller, or pushes a view controller that perhaps shouldn't trigger the same UI change. This way you don't need unnecessary code to check those cases in viewDidDisappear.

Finally, it simply seems appropriate to have in a collections of utilities like ThunderCats, as presentViewController has a completion block (which I very often use), and it simply seems like an oversight that pushViewController doesn't have the same option.

bsmith11 commented 9 years ago

I think what you are looking for is a view controller's transitionCoordinator (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewControllerTransitionCoordinator_Protocol/).

lgauthier commented 9 years ago

@bsmith11 I think we might want to take a more detailed look into this. I can see how these categories could be convenient. However, at the same, I can also see a scenario where they could cause bugs.

For example, if you have code that pops and performs some action during the completion block using one of these category methods, then that code wouldn't get called in the case where the user popped the view controller using the swipe from the side of the screen.

Looks like there might be holes in the category methods that the transitionCoordinator covers more robustly. We'll put some more consideration into it. As of right now, I'm thinking about removing the categories, but I'll let you know if we end up thinking that they do actually have a valid place in ThunderCats