如何在UITableView中检测Cell选择 - Swift [英] How to detect Cell selection in UITableView - Swift
本文介绍了如何在UITableView中检测Cell选择 - Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只是想知道如何在我的应用程序中实现didSelectRowAtIndexPath或类似的东西。
我有一个带有几个动态单元格的填充表视图,基本上我想在选择某个单元格后更改视图。
just wondering how I would go about implementing didSelectRowAtIndexPath or something similar into my app. I have a populated Table View with several dynamic cells and basically I want to change Views once a certain cell is selected.
我能够理解我的头脑在Obj-C周围,但谷歌没有任何东西可以帮助我使用Swift!任何帮助将不胜感激,因为我还在学习
I am able to get my head around it in Obj-C, but there is nothing on google to help me with Swift! Any help would be appreciated as I am still learning
推荐答案
你可以使用 didSelectRowAtIndexPath
在斯威夫特。
You can use didSelectRowAtIndexPath
in Swift.
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
NSLog("You selected cell number: \(indexPath.row)!")
self.performSegueWithIdentifier("yourIdentifier", sender: self)
}
对于Swift 3,它是
For Swift 3 it's
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
NSLog("You selected cell number: \(indexPath.row)!")
self.performSegueWithIdentifier("yourIdentifier", sender: self)
}
请确保实施 UITableViewDelegate
。
这篇关于如何在UITableView中检测Cell选择 - Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文