2014-05-17 77 views
1

我有一個UITextView在我專門用來允許複製/粘貼內容的uitableviewcell中。但是,textView的單擊不會被轉發到tableViewCell。從UITextView轉發到UITableViewCell

有沒有辦法解決這個問題?

+0

你可以添加一個點觸手勢調用調用'selectRowAtIndexPath的方法:從'UITableViewCell'子類中'。見[這裏](http://stackoverflow.com/questions/5997708/uitextview-inside-uitableview) – sooper

回答

2

你可以做這樣的事情:

- (void)textTapped:(UITapGestureRecognizer *)recognizer 
{ 
    // Get the text view from gesture recognizer or some delegate method 
    UITextView *textView = (UITextView *)recognizer.view; 

    UIView *cellToBeSelected = textView.superview; 

    // Try to get the correct cell view according to received view hierarchical. 
    while (![cellToBeSelected isKindOfClass:[UITableViewCell class]]) 
    { 
     cellToBeSelected = [cellToBeSelected superview]; 
    } 

    // Select the cell 
    if (cellToBeSelected) 
    { 
     [self.tableView selectRowAtIndexPath:[self.tableView indexPathForCell:(UITableViewCell *)cellToBeSelected] 
            animated:YES 
           scrollPosition:UITableViewScrollPositionNone]; 
    } 
} 
相關問題