簡體   English   中英

UITableViewCell不響應響應者鏈

[英]UITableViewCell Does not respond to the responder chain

我在開發過程中遇到問題,我有一個UITableViewCell ,它添加了一個UIButtonUIButton充滿了Cell),希望我的UIButton響應我的touchupinside事件,在處理完成后,該事件再次發送touchupinside ,直到Cell到響應didSelectRowAtIndexPath方法。但是現在, didSelectRowAtIndexPath沒有起作用嗎? (注:我不想手動調用didSelectRowAtIndexPath方法,希望通過響應者鏈來解決這個問題)

如果按鈕比單元格小,它將按預期工作:如果觸摸按鈕,則按鈕處理程序將觸發,如果觸摸單元格中的另一個區域,則didSelectRowAtIndexPath觸發。

但是,如果按鈕覆蓋整個單元格,則不是問題。 您可以從按鈕處理程序調用與表視圖委托相同的例程。

- (void)tableView:(UITableView *)tableView 
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   [self doCellThingWithIndexPath:indexPath];
}

- (void)buttonAction:(UIButton*)sender {
    // do whatever the button does, then
    CGRect buttonFrame = [button convertRect:sender.bounds toView:self.tableView];
    NSIndexPath *indexPath = [self.tableView 
                              indexPathForRowAtPoint:buttonFrame.origin];
    [self doCellThingWithIndexPath:indexPath];
}

暫無
暫無

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

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