简体   繁体   中英

Detect touches on UITableView SECTION?

How can i do to detect user touches on table view section?

I tried UITapGestureRecognizer and touchesEnded: without success.

Touch Ended example

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
  UITouch *Touch = [[event allTouches] anyObject];
  if (CGRectContainsPoint([_Sec0 frame], [Touch locationInView:_Table])) {
    NSLog(@"SECTION 0");
  } else if (CGRectContainsPoint([_Sec1 frame], [Touch locationInView:_Table])) {
    NSLog(@"SECTION 1");
}

UITapGestureRecognizer example

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(Tapped:)];
[_Sec0 addGestureRecognizer:tap];
[tap release];

Nothing happened.
Touch is called everywhere on the view except on the table.
Tap gesture are not called.

any idea?

EDIT: of course, there is the delegate.

thanks.

The UITableView is consuming the touches and not sending them down the responder chain.

This means that the touches will not get through to the UIView beneath and trigger your function.

I found this question that might help you...

Stop UITableView consuming touch events so sliding menu in parent view can detect horizontal swipes

What mean touches on section? You can detect selecting of cells and headers with UITableViewDelegate . Can it helps you?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM