Xcode - Swift Programmatically select tablecell

末鹿安然 提交于 2019-12-24 22:38:45

问题


I need to know how to set the state of a tableviewcell to selected via code.

I tried the following:

let cell:TblCell = tableView.cellForRowAtIndexPath(indexPath) as TblCell
cell.selected = false;

But this didn't work, even though it did not give any errors.

Should this have worked? or is this done differently?


回答1:


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

Instead of .Middle you can use .None so the tableView doesn't scroll to the selected cell. .Top and .Bottom are also available options.



来源:https://stackoverflow.com/questions/29007079/xcode-swift-programmatically-select-tablecell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!