Why change class of DetailViewController.xib for touches?


#1

In the Silver challenge of the previous chapter I used the “touchesBegan” method to achieve the same result of dismissing the keyboard when a touch was registered on the DetailViewController view outside of the keyboard. I had a branch that added a Dismiss button manually to the Number Pad window/view but this had some strange behaviors and felt too kludgey overall to be satisfied with it.

Why the change of class and registering a target/action to do this? What are the pros/cons/differences in this case to achieve this same effect?


#2

Using UIControl is overall much simpler, in my opinion. Your approach works fine, but makes some assumptions about the view of the view controller: that is, it doesn’t already implement touchesBegan:withEvent:, which would prevent your view controller from receiving that message. By explicitly saying this view is a UIControl and setting a target-action pair, we can explicitly say “This is exactly what this view is and this is exactly what it does.”


#3

Thank you for the clarification!