【发布时间】:2020-02-21 10:08:36
【问题描述】:
您好,我有两个不同的数组数据需要传递给视图控制器,我的 ViewControllers 设计是相同的,但唯一的区别是数据。我怎样才能做到这一点?这是我的代码
var attendance: [GAttendance]!
var subjectAttendances: [GAttendances]!
// In my A controller
let detailAbsenceVC = DetailAbsenceVC()
detailAbsenceVC.attendance = attendances
self.present(detailAbsenceVC, animated: true)
// In my B controller
let detailVC = DetailAbsenceVC()
detailVC.subjectAttendances = subjectAttendances
self.present(detailVC, animated: true, completion: nil)
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return attendance.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: GStudentAbsenceCell.cellID, for: indexPath) as! GStudentAbsenceCell
let attendanceItem = attendance[indexPath.row]
cell.configureCell(attendance: attendanceItem)
return cell
}
【问题讨论】:
-
所以
tableView位于DetailAbsenceVC中,您希望在此处显示任一来自A/B 的attendance或subjectAttendances数据控制器? -
是的@AndreasOetjen
标签: ios arrays swift uitableview