在我开始之前,让我说,我已经在流行后对此事采取一看:Passing Data between View Controllers斯威夫特
我的项目是在github https://github.com/model3volution/TipMe
我的内一个UINavigationController,因此使用push
segue。
我已验证我的IBAction
方法已正确关联,并且segue.identifier
对应于故事板中的segue标识符。
如果我拿出prepareForSegue:
方法,那么会发生segue,但显然没有任何数据更新。
我的具体错误消息是:Could not cast value of type 'TipMe.FacesViewController' (0x10de38) to 'UINavigationController' (0x1892e1c).
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
if segue.identifier == "toFacesVC" {
let navController:UINavigationController = segue.destinationViewController as! UINavigationController
let facesVC = navController.topViewController as! FacesViewController
facesVC.balanceLabel.text = "Balance before tip: $\(balanceDouble)"
}
}
下面的代码和错误的屏幕截图。 旁注:使用的Xcode 6.3,雨燕1.2
正如另一条评论已经建议:在你的问题中包含代码。我现在为你做了这个,因为提供该项目下载到某处可以让其他用户更容易地帮助你。我喜欢那个:) +1 – luk2302