Search code examples
objective-chittest

Overriding hitTest on UIView


I have an app that is going to have a pretty extensive form in it. Fifty or so entries. My hierarchy looks like this. Because of the overlying views the textfields in the form view do not get a cursor in them when clicked:

viewController.view (UIView)

svParent (UIScrollView)

section(UIView)

titlebar(UIView)/contentWrapper(UIScrollView) (siblings the following are children of contentWrapper)

form(UIView)

textfield(UITextField)

textfield(UITextField)

textfield(UITextField)

...and so on...

I understand the concept of over riding hitTest on a superview so that an object on a subview can be accessed but I'm not exactly sure how to program it.

In my viewController I added this:

 - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {

    NSLog(@"ok");
    return NO;
}

but no matter where I click in the simulator window nothing gets logged. Is there something else I need to do? And then can someone clarify what happens after - is this some automagical thing where when functioning properly the lowest subview will get first responder status and become active (i.e. in the case of a textfield editable).


Solution

  • - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event ;

    AFAIK it is implemented in UIView subclass, and not in view controller.

    For better understanding hierarchy, refer this answer