简体   繁体   中英

Can't select the tableView Cell because of textView

I have got a TableView and each cell is covered by a Text View. I think that because of this reason I can't select any cell.

Whenever I try to print it I don't get anything:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        var i = Int()
        i = indexPath.row
        print("i=\(i)")
    }

**Its print and not println because of Swift 2.0.

Please ensure following:

  1. You are correctly setting your view controller as delegate of the table view.

  2. Your touches are intercepted by text view and are not reaching underneath cell. To fix this set userInteractionEnabled to false in cellForRowAtIndexPath: and set it back to true in didSelectRowAtIndexPath: .

Take a look at UITextView 's userInteractionEnabled , multipleTouchEnabled , and exclusiveTouch . Those properties alter whether or not a view receives touches; if it doesn't, the touches get passed to the view behind it (or at least I think that's how it works). I forget where it is, but there's also a method that's called to ask a view which view should be the target of a specific touch, which would allow you to explicitly tell it to send them to the underlying view.

However, from a design perspective, I would re-evaluate having a UITextView on top of a UITableViewCell - the text view is a scroll view and the cell is in a scroll view, so they will always conflict. UILabel is generally more appropriate for putting in a text view.

For those who are using storyboard just uncheck User Interaction Enabled and Multiple Touch as showing below in the screenshot:

使文本视图不与用户触摸交互

I have listed below points for your solution.

  1. you need to check delegate is connected to your view controller.
  2. next you need to check table view selection is enabled for your table view you can check it from table view attributed inspector.
  3. next make sure user interaction is enabled for your text view.

Hope it will be the right solution for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM