开发者

Why should I implement all event-handling methods, while handling events in a subclass of UIView?

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开发者_如何学Go a good search)


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.


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...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜