UITableView didSelectRowAtIndexPath: not being cal

2019-01-03 11:32发布

I'm having an issue with UITableView's didSelectRowAtIndexPath.

My table is setup so that when I select row it initializes a new view controller and pushes it.

The first time I tap any row in the table, the method does not get called. Once I select another row, it begins to work as normal.

I have verified this by setting a breakpoint on didSelectRowAtIndexPath. When adding an NSLog to the method I see that when I select the second row that finally pushes the new view controller, I see two log statements appear in the console at the same time.

Any suggestions?

12条回答
祖国的老花朵
2楼-- · 2019-01-03 12:08

Also check the selection property of your table view in xib file. Use 'Single Selection' or 'Multiple Selection' as required.

查看更多
虎瘦雄心在
3楼-- · 2019-01-03 12:09

I debated even posting this answer because I think the stars kind of aligned in order for this to manifest itself.

I am having a variation of this problem and have checked the other solutions. On my table view it isn't processing the very last row of my table on the first tap. It highlights it, but didSelectRowAtIndexPath isn't being called. All the other rows work fine. But if I turn the tableview bounce on then it seems to solve the problem (but then you have to deal with a tableview bounce).

查看更多
混吃等死
4楼-- · 2019-01-03 12:13

this issue happens also when you are working with gesture recogniser within a tableView in this case you don't need to remove them, you need only to make sure that your gesture property cancelsTouchesInView = false this is a boolean value affecting whether touches are delivered to a view when a gesture is recognised.

查看更多
【Aperson】
5楼-- · 2019-01-03 12:16

I experienced the following issue:

  • first tap in row -> no effect, no selection, never
  • second tap and following -> correct selection behavior, always

In my case, my error was checking Show Selection on Touch in Interface Builder. You can uncheck it in IB here:

enter image description here

Hope that helps someone

查看更多
相关推荐>>
6楼-- · 2019-01-03 12:17

SWIFT 2

Make sure you have this set to true:

self.tableView.allowsSelection = true

Put this above your right after your viewDidLoad() and before the super.viewDidLoad()

查看更多
姐就是有狂的资本
7楼-- · 2019-01-03 12:22

Any chance you accidentally typed didDeselectRowAtIndexPath?

查看更多
登录 后发表回答