简体   繁体   中英

Is it possible to have a “touchesBegan” on a UITableViewCell?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { touchStartTime = [event timestamp]; }

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    NSTimeInterval touchTimeDuration = [event timestamp] - touchStartTime; 
}

touchStartTime is defined at class level.

Any idea why this won't recognise the touch events?

Thanks for the help!

Yes, this is possible to do. I setup a test project with a custom UITableViewCell subclass and defined the methods in the same way that you have, adding a log to the touchesEnded to print the touchTimeDuration. I ran it in the simulator and it seems to work for me.

How are you determining if your code is recognizing the events?

Personally, from my experience with the UITableView, I don't think that you can use the touch events.

You may have to look into other ways of dealing with this. For example, try using the selection as a helper?

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