簡體   English   中英

當擁有兩個tableview部分時,如何知道選擇了哪一行?

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

我正在嘗試編寫應用程序,但我仍然是一個入門者。 當我在表視圖中添加兩個部分時,我不知道選擇了哪一行,因為不同部分中的同一行最終將具有同一行。 那么我有辦法解決這個問題嗎? 這就是我的故事板的樣子

我用來獲取行號的函數是這樣的

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()

}

使用indexPath.section你用同樣的方法indexPath.row 例:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM