【发布时间】:2018-01-13 22:35:15
【问题描述】:
我得到一个零,我不知道为什么。每次我选择 tableViewController1 并执行 segue 时,它都会崩溃并将错误发送给 tableViewController2。我设置了标识符并将类设置为情节提要中的每个 tableViewController。我想要做的是将数据从tableViewController1 传递到tableViewController2
这是来自tableViewController1
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let magazines = MagazineTableViewController()
magazines.customInit(magazinesindex: indexPath.row, title: topics[indexPath.row])
self.performSegue(withIdentifier: "company", sender: nil)
tableView.deselectRow(at: indexPath, animated: true)
}
这是tableViewController2
let MagazinesData = [//an array containing arrays of magazines]
var magazinesIndex: Int!
override func viewDidLoad() {
super.viewDidLoad()
}
func customInit(magazinesindex: Int, title: String) {
self.magazinesIndex = magazinesindex // this is where the error is
self.title = title
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return MagazinesData[magazinesIndex].count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! MagazineTableViewCell
cell.magazineTitle?.text = MagazinesData[magazinesIndex][indexPath.row]
return cell
}
}
【问题讨论】:
标签: swift uitableview variables segue