【发布时间】:2017-05-26 18:54:49
【问题描述】:
我在尝试向新的 viewController 发送数据时遇到问题。 这一行执行
destination1.path = path
因为我获得了新 ViewController 的路径,所以整数似乎有些问题。
我收到此错误消息:
2017-05-26 20:37:14.442509+0200 订阅[1224:301622] UIView: 0x105d294f0;帧 = (0 0; 414 736);自动调整大小 = W+H; layer = CALayer: 0x17403f360>> 的窗口不等于 Subscription.ViewController2: 0x105d3fcb0> 的视图窗口!
// method to run when table view cell is tapped
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("You tapped cell number \(indexPath.row).")
let index = indexPath.row
performSegue(withIdentifier: "EditSegue1", sender: index)
}
@IBAction func backButton(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
}
// Prepare for next view.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination1 = segue.destination as? ViewController2 {
destination1.path = path
if let index = sender as? Int {
destination1.index = index
}
}
}
我的第二个 viewController。
var path = ""
var index = 0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
print(path)
print(index)
}
【问题讨论】:
-
sender 永远不会是整数。我想你想要的是
sender.tag as? Int -
我认为错误不在 Int 值中,因为这段代码不应该崩溃。我认为这与你的用户界面有关
-
您不应该手动调用 prepare
prepareForSegue:sender:。一旦启动故事板转场,就会自动调用它