0

我在 tableViewCell 中有一个 UITextView

问题是,当我单击 textView 时,它不会执行 didSelectRowAtIndexPath。

但我无法设置 userInteraction = NO 因为我希望能够在长按事件中选择文本

我该如何解决这个问题?

4

1 回答 1

1

我不认为你可以,但是如果你想要的是一种复制单元格内容(文本)的方法,那么如何使用 UITableViewDelegate 来使用官方控件......(比如在你持有单元格的联系人应用程序中) ...

您可以通过实现以下方法来实现它:

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row == 1) { //eg, we want to copy or paste row 1 on each section
        return YES;
    }
    return NO; //for anything else return no
}


- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {

    if (action == @selector(copy:)) { //we want to be able to copy

        if... //check for the right indexPath
            return YES;

    }

    return NO; //return no for everything else

}


- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {

    if (action == @selector(copy:)) {

         //run the code to copy what you want here for indexPath

    }

}

只是从内存中写的,所以 @selector(copy:) 可能是 @selector(copy) (否 :) 但试试看......你也可以添加额外的任务,比如粘贴等,但我会让你弄清楚。

祝你好运

于 2012-05-05T19:45:17.103 回答