![](/img/trans.png)
[英]Custom UITableViewCell didSelectRowAtIndexPath not being called
[英]didSelectRowAtIndexPath; UITapGestureRecognizer; custom UITableViewCell
我有一個麻煩w /從表格單元格傳遞到tableView
或說簡單didSelectRowAtIndexPath
沒有被調用。
我創建自定義UITableViewCell
。 它有兩個手勢識別器
UIGestureRecognizer* panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
panRecognizer.delegate = self;
[self addGestureRecognizer:panRecognizer];
panRecognizer.cancelsTouchesInView = NO;
UIGestureRecognizer* tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapRecognizer.delegate = self;
[self addGestureRecognizer:tapRecognizer];
tapRecognizer.cancelsTouchesInView = NO;
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
return YES;
}
但是盡管cancelsTouchesInView=NO
問題,但是還沒有調用cancelsTouchesInView=NO
didSelectRowAtIndexPath
。 而且我關閉了細胞內所有物體的相互作用。 喜歡
userInteractionEnabled = NO
但它沒有幫助。 似乎tableview沒有觸摸...另一方面,單元格手勢識別器內部工作得很好。
有沒有人有什么想法為什么didSelectRowAtIndexPath
無法工作?
提前致謝。
編輯:似乎問題不在UIGestureRecognizer
。 我試圖刪除它們,但它沒有幫助。 UITableView
獲得平移手勢(因為工作滾動),但點擊手勢消失了...
有沒有辦法調試手勢事件?
每次需要在TableViewCell中定義自定義難處理元素時,您需要編寫協議UITableViewCellDelegate並將表分配為每個單元格的委托
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CustomTableViewCellIdentifier forIndexPath:indexPath];
cell.delegate = self;
. . . . . . .
}
- (void) tableViewCell:(UITableViewCell*)tableViewCell gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer
{
CGPoint locationInCell = [gestureRecognizer locationInView: tableViewCell];
. . . . . . .
}
這里的類型是交互類型的枚舉 - 點擊或平移。
然后,您需要在handlePan和handleTap單元格方法中使用適當的類型調用此協議方法。
你可以嘗試這個..
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
if ([gestureRecognizer view] isKindOfClass:[UITableViewCell class]
return NO;
return YES;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.