Search code examples
objective-cuitextviewuser-interaction

disable userinteraction for single tap on uitextview


I've got a UITextView in a tableViewCell

The problem is that when I single tap on the textView it doesn't perform the didSelectRowAtIndexPath.

But I can't set userInteraction = NO because I want to be able to select the text on a long press event

How can I solve this?


Solution

  • I don't think you can so that however if what you want is a way to copy content (text) of a cell how about using the UITableViewDelegate to use the official controls... (like in contacts app where you hold the cell)...

    You can achieve it by implementing these methods:

    - (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
    
        }
    
    }
    

    Just wrote that from memory so @selector(copy:) might be @selector(copy) (no :) but try it out... You can also add addtional tasks like paste ect but I'll let you figure that out.

    Good luck