开发者

why does this touchesBegan method code get trigger in my UITableView?

开发者 https://www.devze.com 2023-02-20 09:30 出处:网络
Why does the touchesBegan method code get trigger in my UITableView? Background:I have a UITableView within a UINavigationController.In the UITableView I have custom cells based on subclassing UITabl

Why does the touchesBegan method code get trigger in my UITableView?

Background: I have a UITableView within a UINavigationController. In the UITableView I have custom cells based on subclassing UITableViewCell. I current don't have a selectRowAtIndexPath method in my UITableView.

Some aspects of the answer that would be good to cover off would include:

  • why it doesn't work obviously

  • in terms of getting it to work, how does get one ensure that the correct touch (single-tap) detection will not prevent the other scenarios to work like: selecting a table row, scrolling the tableview contents up and down etc.

  • should the simulator be able to pick up touches etc, or are there cases here where you need the physical device

Code:

@interface AppointmentListController : UITableViewController <UIActionSheetDelegate> 
.
.
.

@implementation AppointmentListController
.
.
.

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

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
        NSTimeInterval timeStampEnd = event.timestamp;
        NSTimeInterval touchDuration = timeStampEnd - timeStampStart;

        if(touchDuration > 0.2)
            [super touchesEnded:touches withEvent:event];
        else
            DLog(@" - TOUCH EVENT OCCURS");

    开发者_JAVA百科    [super touchesEnded:touches withEvent:event];
    }


Wanted to put up this as a possible answer, the answer being there is no relative straight way to achieve what I've asked for this. That is a way for a tap or double-tap to be detected in a UITableView page, which is already picking up row touches and scroll up/down etc.

Haven't verified whether this is the case or not, but people could up-vote this answer if they believe this to be true.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号