[英]How can I get the index path.row of first UITableView in the Second UITableView using Swift3
我有兩個UITableView
。 第一個UITableView
包含一個數據數組,第二個為空。 如何獲取第一個表的索引路徑,以便在第二個表中使用它來查看不同的數據? 這是我要在第二個表中執行的示例:
這在第二個表中,並且像此函數一樣,我要在其中獲取第一個表的indexPath.row
。
func loadData() {
if indexPath.row == 0 { // (of first table)
// add code
} else if indexPath.row == 1 { // (of first table)
// add code
}
}
實現didSelectRowAt
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
let selctedIndex = indexPath.row
self.setIndexToSecondTableView(selctedIndex) //Create your function to get selected index of first table view
}
希望您能找到解決方案。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
if tableView.isEqual(firstTableView) {
self.updateScecondTableView(index: IndexPath.row) //make a function to retrieve selected index from first table view
} else {
// acode
}
}
func updateScecondTableView(index:NSIndexPath) {
switch index.row {
case 0:
// add a code
break
default:
// add a code
break
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.