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条回答
可以哭但决不认输i
2楼-- · 2019-01-03 12:25

SWIFT 3

If you are working with Swift 3 in a class which isn't a UITableViewController and you are using UITableViewDelegate, then you may need to use the method title:

@objc(tableView:didSelectRowAtIndexPath:) func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){...}

This worked for me, although I have just migrated my project to Swift 3. It's fairly new so this may be fixed later.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-01-03 12:25

didSelectRowAt function was not called in my app in first or second tap... I was trying to solve the problem could not find any solution. But suddenly ı was recognise, I was using view.animation color change... Delegate method was not called while animation persist

查看更多
别忘想泡老子
4楼-- · 2019-01-03 12:30

SWIFT 3

None of the other answers worked in my case, what fixed it for me was:

tableView.delaysContentTouches = false

查看更多
SAY GOODBYE
5楼-- · 2019-01-03 12:31

UITableViewCellSelectionStyleNone was set for the cell displaying that problem (ios9).

I have ended up calling

[tableView deselectRowAtIndexPath:indexPath animated:NO];

first thing in

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

which is not the same, but is good enough. makes me wonder what kind of table breakage ios10 brings.

查看更多
Viruses.
6楼-- · 2019-01-03 12:34

Check If you have set any Gesture recognisers in your class. Removing gesture worked for me.

查看更多
来,给爷笑一个
7楼-- · 2019-01-03 12:35

If you have set any UITapGestureRecognizer in your class, you can add this line in your didSelectRowAtIndexPath:

[tableView deselectRowAtIndexPath:indexPath animated:NO];

This worked for me.

查看更多
登录 后发表回答