rihurla
rihurla

Reputation: 403

iOS UITextView doesn't allow UITableViewCell to be selected

i have a UITableViewCell, and inside of it, i have a UITextView with some text, and it must remain scrollable so i can't remove the user interaction in it.

But the problem is, when i tap the screen, this cell must be selectable as well. Since the UITextView is in front of the cell touch area i'm unable to do that.

I've try to place a UITapGestureRecognizer into the UITextView inside the cell class but i don't know which method to call to select the cell, ending on the UITableView delegate (didSelectRowAtIndexPath) in the main class.

Does Anyone can help me with that, or have other ideas how i can sort this out?

Thanks a lot in advance!

//CUSTOM CELL CODE

-(void)awakeFromNib
{
    self.backgroundColor = [UIColor clearColor];

    self.title.font = [UIFont fontWithName:FONT_MEDIUM size:14];
    self.title.textColor = [UIColor colorWithRed:181/255.0 green:181/255.0 blue:179/255.0 alpha:1];
    self.text.font = [UIFont fontWithName:FONT_LIGHT_ITA size:13];
    self.text.textColor = [UIColor colorWithRed:236/255.0 green:220/255.0 blue:0/255.0 alpha:1];

    UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(touchAction:)];
    [self.text addGestureRecognizer:tap];

}

-(void)touchAction:(UITapGestureRecognizer*)sender{
    NSLog(@"Touch");
}

-(void)setSelected:(BOOL)selected animated:(BOOL)animated
{

    [super setSelected:selected animated:animated];

}

Upvotes: 0

Views: 788

Answers (1)

Seryozha
Seryozha

Reputation: 1639

have you tried this way ?

without disabling textView's user interaction set UITextView's delegate, implement UITextViewDelegate's textViewShouldBeginEditing method like this

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
    [self.tableView selectRowAtIndexPath:yourCellIndexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
    return NO;
}

documentation says "When the user performs an action that would normally initiate an editing session, the text view calls this method first to see if editing should actually proceed."

Upvotes: 1

Related Questions