1

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

2 Answers 2

3

- (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

8
  • I get what your saying but its kind of adding to my confusion -- I have viewController, which instantiates a subclass of VC, and then within that I am adding the subviews. So the hierarchy looks like this VC-->VC~UIScrollV~UIView~UIScrollV - should I can the second VC and go directly to the scroll view and implement the hit test override there? (The ~ mean that view is being instantiated in the code)
    – PruitIgoe
    Oct 10, 2012 at 18:28
  • You need to subclass your views, and there you need to override it, can you tell me your purpose ?? Oct 10, 2012 at 18:32
  • I'm building an accordion type of view to manage a large form, sections are hidden except for titlebars, click a titlebar and the whole section is revealed. I wasn't getting to the textfields within each section.
    – PruitIgoe
    Oct 10, 2012 at 18:42
  • I think that can be easily implemented, use touches events. Oct 10, 2012 at 18:45
  • 1
    U can also use gesture recognizers to handle such cases, Oct 10, 2012 at 18:46
3

First of all, hitTest: is a method of UIView, not UIViewController, so you need a custom UIView subclass somewhere (probably at the top) in your view hierarchy.

Second, the method is supposed to return a view, not a BOOL, so returning NO doesn't make much sense.

1
  • I was messing with hitTest and pointInside and forgot to clean it up when I posted, hence the bad return. I obviously got myself confused on where to implement the method. Haven't really had to do hitTesting before...(obviously) : D
    – PruitIgoe
    Oct 10, 2012 at 18:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.