-1

I have an iPad app (XCode 4.6, Storyboards, iOS 6.2). I have a scene made up like this:

  1. UIView (subViewData - covers the right quadrant of #2, below and to the right not covering the times and names of #2- contains appointment info (cust name, and the duration is shaded)
  2. UIView (subViewGrid - covers bottom half (in image, it contains times on the left margin and names across the top margin.)
  3. UIScrollView (covers the bottom half view)
  4. UIView ------- UIView (one on the top half of the window, the other on the bottom half)
  5. UIViewController (named CalendarViewController)

calendar and sechedule

This is the code to initialize the UITapGestureRecognizer found in -viewDidLoad of the CalendarViewController:

    //  setup for tap recognizer
UITapGestureRecognizer *fingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                    action:@selector(singleFingerTap:)];
fingerTap.numberOfTapsRequired = 1;
fingerTap.numberOfTouchesRequired = 1;
[subViewData addGestureRecognizer:fingerTap];

This is the code in subViewData (#1) that is NOT getting executed:

- (void)singleFingerTap:(UITapGestureRecognizer*)gesture {

CGPoint pt = [gesture locationInView:self];
UIView *v = [self hitTest:pt withEvent:nil];

if(v.tag == 100)  //  if this is for calendar, return
    return;

CGRect dataRect = CGRectMake(110.0,48.0,670.0,1450);
CGPoint dataPoint = CGPointMake(pt.x, pt.y);

//  check to see if point is within the rectangle
if(!CGRectContainsPoint(dataRect, dataPoint))  {
    NSLog(@"\n\nNOT within subViewData");
    return;
}
else  {
    NSLog(@"\n\nIS within subViewData");
}

}

The question is why is it not capturing the taps? Is the recognizer code supposed to be in the controller or the view that is supposedly getting the taps? I have read almost everything I can find on the subject, but can't find anything within this specific scenario. Help is greatly appreciated.

SpokaneDude
  • 4,856
  • 13
  • 64
  • 120

1 Answers1

2

You say:

This is the code to initialize the UITapGestureRecognizer found in -viewDidLoad of the CalendarViewController

And that code says:

 [[UITapGestureRecognizer alloc] initWithTarget:self
                                action:@selector(singleFingerTap:)];

Then you must put singleFingerTap: in CalendarViewController, because you have told the gesture recognizer that the target is self, and self is an instance of CalendarViewController.

You also say:

This is the code in subViewData (#1) that is NOT getting executed

But I do not know what "in subViewData" means; you did not mention anything called "subViewData" in your explanation of the interface. Anyway it doesn't matter. You've specified self so the code needs to be in self.

However, it sounds to me as if the view in question is never receiving the touch at all. Perhaps it is not exposed (i.e. it's covered by another view). Perhaps its userInteractionEnabled is NO. There could be lots of reasons.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I clarified the qustion, giving names to the subViews... there should be NO logical reason the taps are not being captured. I should mention that I am "drawing" on the subViewData (that's how I get the appointment info into the subViewData... it also has an Alpha of .2 for what it's worth. – SpokaneDude Apr 19 '13 at 01:58
  • Negatory? lol... I haven't heard that term in many, many years! – SpokaneDude Apr 19 '13 at 02:00
  • Oh... OK just for laughs give it an alpha of 1 temporarily. Reason: a low alpha prevents taps, so perhaps you are below the threshold. – matt Apr 19 '13 at 02:01
  • I'm wondering if it's time to request help from Apple's Developer Support folks (the ones you pay $99 USD per year to)... – SpokaneDude Apr 19 '13 at 02:01
  • Don't waste your money. :) Do as I suggest. Give subViewData an alpha of 1. And maybe just draw it jetblack, so you can see that you are tapping on the view you think you are. – matt Apr 19 '13 at 02:02
  • OK try this. Remove *all* implementations of `- (void)singleFingerTap:` everywhere in your code. When you create the tap gesture recognizer, set the tap gesture recognizer itself as the target. If the taps are working, you should crash when you tap. – matt Apr 19 '13 at 02:10
  • You're the man! It did crash, and when I looked at the code I found this: [subViewData addGestureRecognizer:fingerTap]; which of course should have been self.view... Thank you so much for your help... probably would have found it eventually, but you saved my bacon... have a good evening. SD – SpokaneDude Apr 19 '13 at 02:17