Xcode-Swift以编程方式选择表格单元 [英] Xcode - Swift Programmatically select tablecell

查看:52
本文介绍了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以编程方式选择表格单元的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆