How to detect cell selection in UITableView in Swift?(如何在 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 中的单元格选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Swift 中检测 UITableView 中的单元格选择?


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01