UITableViewCell selector setSelected:animated: gets called many times?

前端 未结 4 575
野趣味
野趣味 2021-01-31 19:56

I\'ve discovered a strange behavior with setSelected:animated: in my custom UITableViewCell class. I discovered that this function gets called multiple times if

4条回答
  •  星月不相逢
    2021-01-31 20:30

    Ideally you should not be calling setSelected from anywhere in your code. UIKit will take care of calling it.

    If you want to show a cell/row as selected in cellForRowAtIndexPath method simply call

    tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: .None)
    

    for that specific indexPath.

    Again never ever call setSelected explicitly unless you really mean to.

提交回复
热议问题