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:
You are correctly setting your view controller as delegate of the table view.
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.
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.