[英]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.