嘗試將數據發送到新的viewController時遇到問題。 該行執行Segue傳遞整數
destination1.path = path
因爲我得到的路徑,新的ViewController,似乎是有些問題的整數。
我得到這個錯誤消息:
2017年5月26日20:37:14.442509 + 0200訂閱[1224:301622]的UIView:0x105d294f0; frame =(0 0; 414 736); autoresize = 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.tag as? Int' –
我認爲錯誤不在Int值中,因爲這段代碼不應該崩潰。我認爲這是你的東西UI –
你不應該手動準備prepareForSegue:sender:'。一旦啓動故事板,就會自動調用它 –