views:

29

answers:

2

According to the iPhone Application Programming Guide (Event-Handling chapter) I should implement all event-handling methods (even if it is a null implementation), if I work with UIView or UIViewController. And I shouldn't call the superclass implementation of these methods.

Why? (I've searched in the Guide and in Google, but can't find the answer... or just can't make a good search)

A: 

there are many thing in the view which is decided run time by user... by its delegate method... and if it is not defined there are chances that your application will crash...

For example if you have one application and you are using UITableView in it and if you do not implement

tableView:cellForRowAtIndexPath:

It won't give you any error... but when you run the application and when view containing Tableview loads application will crash and you will get

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

Because application does not know how to show cell of the table...

So it would be the same case with UIView and UIViewController... If particular delegate method not implemented your application may be crash on certain event (may be not...)

mihirpmehta
+2  A: 

From the guide:

The reason for this guideline is simple: All views that process touches, including your own, expect (or should expect) to receive a full touch-event stream. If you prevent a UIKit responder object from receiving touches for a certain phase of an event, the resulting behavior may be undefined and probably undesirable.

jessecurry
But why it wasn't possible to make default (null) implementations of these touches (to allow only necessary implementations in the supposed subclass)?
kpower
I don't believe that it was impossible, but the designers probably decided that they would not implement null methods... or maybe the team that added the touch handling did not have access to the original UIView code (or were not allowed to modify it).
jessecurry
kpower