簡體   English   中英

UITableViewCell做了電子事件延遲

[英]UITableViewCell didselectrow event delay

我在UITableViewCellUITableView 我之前做了大約一千次,但現在我想抓住這個委托活動:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath;

觸摸單元格時,應調用此回調。 但我只是在觸摸后按下6秒或6次,但不是每次觸摸都會調用。

tableview是子類UIView的子視圖,我在awakeFromNib調用它:

-(void)awakeFromNib{
_table_view.delegate = self;
_table_view.dataSource = self;
}

tableview自己很好,但這個事件運作不佳。 有任何想法嗎?

這是UITableViewCell子類代碼.m

#import "FLBlockedPersonCell.h"

@implementation FLBlockedPersonCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    [super setHighlighted:highlighted animated:animated];
}



@end

也許您在視圖上添加UITapGestureRecognizer,當您觸摸它時,UITapGestureRecognizer首先響應。

當觸摸單元格時,應該發生以下調用:

-(void) tableView:(UITableView*) tableView didHighlightRowAtIndexPath:(NSIndexPath*) indexPath

只有在您真正選擇了一個單元格時才會調用didSelect,而不僅僅是單擊它。 還有一些像shouldHighlight和willSelect這樣的方法會在觸摸時調用。

首先,確保tableView.allowsSelection設置為YES

聽我說UITableView是子視圖的UIView阻止了觸摸事件。

您需要確保UIView子類沒有捕獲任何觸摸事件。 我會從你的UIView子類中刪除任何這些方法:

touchesBegan:withEvent: 
touchesMoved:withEvent: 
touchesEnded:withEvent: 
touchesCancelled:withEvent:

如果你實現這個方法我也會返回NO:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    return NO;
}

你真的不應該重寫這些方法:

hitTest:withEvent:
pointInside:withEvent:

如果您是,請質疑原因並刪除它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM