如何在 Swift 中检测 UITableView 中的单元格选择? [英] How to detect cell selection in UITableView in Swift?

查看:18
本文介绍了如何在 Swift 中检测 UITableView 中的单元格选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的 Swift 应用中实现 didSelectRowAtIndexPath: 或类似的东西?

How can I implement didSelectRowAtIndexPath: or something similar in my Swift app?

我有一个包含多个动态单元格的填充表格视图,我想在选择某个单元格后更改视图.

I have a populated Table View with several dynamic cells and I want to change views once a certain cell is selected.

我可以在 Objective-C 中理解它,但在 Swift 上没有任何东西可以帮助我!

I am able to get my head around it in Objective-C, but there is nothing on google to help me with Swift!

推荐答案

你可以在 Swift 中使用 didSelectRowAtIndexPath:

You can use didSelectRowAtIndexPath in Swift:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    NSLog("You selected cell number: (indexPath.row)!")
    self.performSegueWithIdentifier("yourIdentifier", sender: self)
}

只要确保你实现了 UITableViewDelegate.

这篇关于如何在 Swift 中检测 UITableView 中的单元格选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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