是的你可以。
老问题,但我会使用 swift 快速回答
首先你打电话
performSegueWithIdentifier("<#your segue identifier #>", sender: <#your object you wish to access in next viewController #>)
在prepareForSegue
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let dest = segue.destinationViewController as! <# your destination vc #>
dest.<# sentThroughObject #> = sender
}
}
然后在vc中你segue有一个var来接受传递的对象
class NextViewController: UIViewController {
var <# sentThroughObject #> = AnyObject!()
//cast <# sentThroughObject #> as! <#your object#> to use
}
更新:斯威夫特 3
performSegue(withIdentifier: "<#your segue identifier #>", sender: <#Object you wish to send to next VC#>)
override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
let destination = segue.destinationController as! <# cast to your destination VC #>
destination.sentViaSegueObject = sender as? <#your object#>
}
在目标 VC 中有一个属性来接受发送的对象
var sentViaSegueObject = <#your object#>?