本文介绍了Xcode-Swift以编程方式选择表格单元的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道如何通过代码将tableviewcell的状态设置为选中状态。
I need to know how to set the state of a tableviewcell to selected via code.
我尝试了以下操作:
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?
推荐答案
tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: .Middle)
而不是。Middle
您可以使用 .None
,因此tableView不会滚动到选定的单元格。也可以使用。顶部
和。底部
。
Instead of .Middle
you can use .None
so the tableView doesn't scroll to the selected cell. .Top
and .Bottom
are also available options.
这篇关于Xcode-Swift以编程方式选择表格单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!