简体   繁体   English

当拥有两个tableview部分时,如何知道选择了哪一行?

[英]How to know which row has been selected when having two sections of the tableview?

I am trying to program an app but I'm still a starter. 我正在尝试编写应用程序,但我仍然是一个入门者。 When I added two sections in the tableview, I could not know which row I have selected since the same row in different sections will end up having the same row. 当我在表视图中添加两个部分时,我不知道选择了哪一行,因为不同部分中的同一行最终将具有同一行。 So is there a way for me to solve this problem? 那么我有办法解决这个问题吗? this is how my storyboard looks like 这就是我的故事板的样子

The function I used to get the row number is like this 我用来获取行号的函数是这样的

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    NSLog("You selected cell number: \(indexPath.row)!")
    var alertView = UIAlertView()
    alertView.addButtonWithTitle("Ok")
    alertView.title = "Row Selected"
    alertView.show()

}

Use indexPath.section in the same way you use indexPath.row . 使用indexPath.section你用同样的方法indexPath.row Example: 例:

if indexPath.section == 0 and indexPath.row == 0 {
//Do something when the first section's first row is selected
}

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

相关问题 如何知道是否已选择UITableView中的行? - How to know if a row in a UITableView has been selected? 如何知道在哪个表格单元格中触摸了哪个图片? - How to know which pic in which tableview cell has been touched? 如何设置表视图中的选定行的背景颜色,即子表视图? - How to set the background color of selected row in tableview which is child tableview? 如何了解已选择哪个UITableViewCell - How to understand which UITableViewCell has been selected 如何检查已选择哪个UIButton - how to check which UIButton has been selected 如何使已选择为Vine App的无颜色的Tableview单元格 - How to make the tableview cell that has been selected to no color as Vine App 当按下TableView单元格中的按钮时,我怎么知道按下了哪一行单元格的按钮? - When the button in TableView cell pressed, how do I know the button of which row of cell pressed? 当使用多个部分时,如何动画化tableView单元格的删除/添加,而部分的数量可能会发生变化 - How to animate the removal/addition of tableView cells when using multiple sections while the number of sections has the possibility of changing 我怎么知道 Instagram 按钮已被选中? - How do I know that the Instagram button has been selected? 加载TableView后,将UITableView中的单元格分为几节 - Sorting cells in UITableView into sections, after TableView has been loaded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM