简体   繁体   English

从不同场景返回时,静态tableview单元格保持突出显示

[英]Static tableview cell stays highlighted when returning from different scene

I have a uiviewcontroller with a container on it, embedded inside of that is a uitableviewcontroller that has static cells and static content. 我有一个带有容器的uiviewcontroller,嵌入其中的是一个具有静态单元格和静态内容的uitableviewcontroller。 When I tap the cell "Trip Info" it segues to the Trip Info View Controller. 当我点击“旅行信息”单元时,它会提示到“旅行信息视图控制器”。 When coming back the static cell is highlighted. 回来时,静态单元格突出显示。

I have seen many posts saying to add code to the didselectrow tableview method but I dont use one because my content is static. 我看到很多帖子都说要向didselectrow tableview方法添加代码,但是我不使用它,因为我的内容是静态的。 Any ideas? 有任何想法吗?

Okay, just because you have static content doesn't mean you get to skip using the tableview delegate. 好的,仅仅因为您拥有静态内容并不意味着您可以跳过使用tableview委托。 It's not hard to set up. 设置起来并不难。

 tableView.deselectRowAtIndexPath(index)

There's not another way. 没有别的办法了。

I ended up figuring it out on my own. 我最终自己弄清楚了。

You need to make a swift file for that UITableViewController that is embedded into the UIViewController. 您需要为嵌入到UIViewController中的UITableViewController创建一个快速文件。

Then make sure your tableview is a delegate, and then call the 然后确保您的表视图是一个委托,然后调用

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true)
}

in that new file you created. 在您创建的新文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM