OGeek|极客世界-中国程序员成长平台

标题: ios - UITableView 项目被突出显示,然后被取消选择 - Swift [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:57
标题: ios - UITableView 项目被突出显示,然后被取消选择 - Swift

我有一个带有 3 个嵌套 UIView 的 UIView。它们的总宽度是屏幕的 300%。 (每个 100%)。 我正在更改 AutoLayout 优先级,以便通过从 NavBar 中单击按钮将所需的内容显示在屏幕上,并将其他内容显示在屏幕外。

|uiview1| |uiview2| |uiview3|

uiview3 有一个 UITableView。它填充,完美滚动,但是在点击一个项目时,该项目会突出显示一秒钟然后释放。没有调用函数“didSelectRowAt”。

我已尝试禁用在此 VC 上注册的所有其他手势。点击也会被检测到,但不会持续存在并立即被取消选择。

//globally in VC
@IBOutlet weak var salamsTable: UITableView!

//in viewDidLoad
self.salamsTable.delegate = self
self.salamsTable.dataSource = self

//delegate functions
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
    print (indexPath.row)  // this never gets called
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{
    return self.allSalam.count      //works perfectly
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
{
    var cell = self.msgsTable.dequeueReusableCell(withIdentifier: "messages") as! MessageCell
    return cell // works perfectly
}

salamsTable is the subject UITableView

视觉演示:

enter image description here



Best Answer-推荐答案


不是解决方案,而是替代方案。事情以另一种方式解决了。正如您在问题中附加的演示 GIF 中看到的那样,单元格被正确突出显示。所以我添加了委托(delegate)方法 didHighlightRowAt,它就像一个魅力。

关于ios - UITableView 项目被突出显示,然后被取消选择 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46655410/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4