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

PruitIgoe
  • 6,166
  • 16
  • 70
  • 137

2 Answers2

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

Community
  • 1
  • 1
DivineDesert
  • 6,924
  • 1
  • 29
  • 61
  • 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 '12 at 18:28
  • You need to subclass your views, and there you need to override it, can you tell me your purpose ?? – DivineDesert Oct 10 '12 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 '12 at 18:42
  • I think that can be easily implemented, use touches events. – DivineDesert Oct 10 '12 at 18:45
  • 1
    U can also use gesture recognizers to handle such cases, – DivineDesert Oct 10 '12 at 18:46
  • Won't touches just work on the top layer though? (http://mobile.tutsplus.com/tutorials/iphone/ios-quick-tip-detecting-touches/) Or is it like pointInside and allows you to drill down? – PruitIgoe Oct 10 '12 at 18:49
  • Oh for the love of God, that's what I'm using to open and close the sections...(gestures)...forest, trees, doh...sometimes you should just walk away from the keyboard and take a break... : D – PruitIgoe Oct 10 '12 at 18:51
  • :D Great , Happy to help, I am retiring my day, you too go to your bed, Else probably you will mess up things :) – DivineDesert Oct 10 '12 at 18:52
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.

omz
  • 53,243
  • 5
  • 129
  • 141
  • 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 '12 at 18:42