【发布时间】:2020-04-05 10:14:31
【问题描述】:
根据显示的视频,我希望 TransactionListViewController 显示从 AccountViewController 中选择的单元格。
但是,TransactionViewController 仅显示 Section 0 Row 0 和 Section 0 Row 1,而其他部分和行继续显示 Section 0 Row 1
预期结果
Section 0, Row 0 将为 Section 0, Row 0 执行 segue 和 pull 数据
Section 0, Row 1 将为 Section 0, Row 1 执行 segue 和拉取数据
Section 1, Row 0 将为 Section 1, Row 0 执行 segue 和 pull 数据
Section 1, Row 1 将为 Section 1, Row 1 执行 segue 和拉取数据
第 2 节第 0 行将为第 2 节第 0 行执行 segue 和拉取数据
第 2 节第 1 行将为第 2 节第 1 行执行 segue 和拉取数据
#AccountTableViewController
var accTypePA : Results<AccTypePA>?
var accTypeCA : Results<AccTypeCA>?
var accTypeInv : Results<AccTypeInv>?
var accTypeAss : Results<AccTypeAss>?
var accTypeLbty : Results<AccTypeLbty>?
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
if indexPath.section == 0 {
let strAccountPA = accTypePA
selectedPA = strAccountPA?[indexPath.row]
performSegue(withIdentifier: "SegToTransactionPage", sender: indexPath.row)
} else if indexPath.section == 1 {
let strAccountCA = accTypeCA
selectedCA = strAccountCA?[indexPath.row]
performSegue(withIdentifier: "SegToTransactionPage", sender: indexPath.row)
} else if indexPath.section == 2 {
let strAccountCA = accTypeCA
selectedCA = strAccountCA?[indexPath.row]
performSegue(withIdentifier: "SegToTransactionPage", sender: indexPath.row)
} else if indexPath.section == 3 {
let strAccountCA = accTypeCA
selectedCA = strAccountCA?[indexPath.row]
performSegue(withIdentifier: "SegToTransactionPage", sender: indexPath.row)
} else if indexPath.section == 4 {
let strAccountCA = accTypeCA
selectedCA = strAccountCA?[indexPath.row]
performSegue(withIdentifier: "SegToTransactionPage", sender: indexPath.row)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if(segue.identifier == "SegToTransactionPage") {
if let transactionVC = segue.destination as? TransactionTableViewController {
transactionVC.selectedPA = self.selectedPA
transactionVC.selectedCA = self.selectedCA
transactionVC.selectedInv = self.selectedInv
transactionVC.selectedAss = self.selectedAss
transactionVC.selectedLbty = self.selectedLbty
}
}
}
# TransactionListTableViewController
var selectedPA : AccTypePA?
var selectedCA : AccTypeCA?
var selectedInv : AccTypeInv?
var selectedAss : AccTypeAss?
var selectedLbty : AccTypeLbty?
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
print("Selected section 0 : \(section)")
return selectedPA?.transPAList.count ?? 0
} else if section == 1 {
print("Selected section 1 : \(section)")
return selectedCA?.transCAList.count ?? 0
} else if section == 2 {
print("Selected section 2 : \(section)")
return selectedCA?.transCAList.count ?? 0
} else if section == 3 {
print("Selected section 3 : \(section)")
return selectedCA?.transCAList.count ?? 0
} else if section == 4 {
print("Selected section 4 : \(section)")
return selectedCA?.transCAList.count ?? 0
}
return transactions?.count ?? 1
}
【问题讨论】:
-
调用 segue 时,每次只传递行
performSegue(withIdentifier:SegToTransactionPage", sender: indexPath.row)`。它不知道是哪个部分,因此它始终为 0 . 你还需要告诉它是什么部分indexPath.section
标签: swift realm tableview segue didselectrowatindexpath