swift segue

2018-04-27  本文已影响15人  倾倒的吞天壶
  1. segue定义:转场对象
  2. 属性:标识,源对象,目标对象
  3. 类型:手动型,自动型
    手动型:手写代码执行
// Segue必须由来源控制器来执行,也就是说,这个perform方法必须由来源控制器来调用  
[self performSegueWithIdentifier:@"login2contacts" sender:nil];  

自动型:点击按钮自动执行

  1. 传数据
 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }

顺传:
在源控制器中的prepareForSegue:sender:方法中根据segue参数取destinationViewController,也就是目标控制器,直接给目标控制器传递数据。
逆传:
让源控制器成为目标控制器的代理,在目标控制器中调用源控制器中的代理方法,通过代理方法的参数传递数据给源控制器。

上一篇下一篇

猜你喜欢

热点阅读