Ios 从自定义序列传递数据
我已经创建了一个自定义segue,我想知道在哪里放置Ios 从自定义序列传递数据,ios,swift,segue,Ios,Swift,Segue,我已经创建了一个自定义segue,我想知道在哪里放置func prepareforsgue,以便执行它 class CustomSegue: UIStoryboardSegue { var a = 0 var b = 0 override func perform() { func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { let DestViewController : View
func prepareforsgue
,以便执行它
class CustomSegue: UIStoryboardSegue {
var a = 0
var b = 0
override func perform() {
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let DestViewController : ViewController = segue.destinationViewController as! ViewController
DestViewController.unlock = a + 10
DestViewController.lock = b + 10
}
let source1 = sourceViewController as UIViewController
let destination1 = destinationViewController as UIViewController
let window = UIApplication.sharedApplication().keyWindow!
destination1.view.alpha = 0.0
window.insertSubview(destination1.view, belowSubview: source1.view)
UIView.animateWithDuration(0.5, animations: { () -> Void in
source1.view.alpha = 0.0
destination1.view.alpha = 1.0
}) { (finished) -> Void in
source1.view.alpha = 0.0
source1.presentViewController(destination1, animated: false, completion: nil)
}
}
}
此代码执行segue,但不将值传递给
DestViewController
-(它不执行func prepareforsgue
)如果您的自定义segue仅为一个视图编写,请执行以下操作:
class CustomSegue: UIStoryboardSegue {
var a = 0
var b = 0
override func perform() {
if let destViewController = destinationViewController as? ViewController {
destViewController.unlock = a + 10
destViewController.lock = b + 10
}
let source1 = sourceViewController as UIViewController
let destination1 = destinationViewController as UIViewController
let window = UIApplication.sharedApplication().keyWindow!
destination1.view.alpha = 0.0
window.insertSubview(destination1.view, belowSubview: source1.view)
UIView.animateWithDuration(0.5, animations: { () -> Void in
source1.view.alpha = 0.0
destination1.view.alpha = 1.0
}) { (finished) -> Void in
source1.view.alpha = 0.0
source1.presentViewController(destination1, animated: false, completion: nil)
}
}
}
如果不是,请将
prepareforsgue
函数移到ViewController之前的上一个视图控制器。prepareforsgue
是UIViewController函数,而不是UIStoryboardSegue::