标签:bsp touch sel 导航 message 导航栏 info navig red
这里是我需要的两个Controller,从FirstVC跳转到TwoVC,TwoVC返回的时候给FirstVC传递参数
let vc = UINavigationController.init(rootViewController: FirstVC()) let rootVC = UIApplication.shared.delegate as! AppDelegate rootVC.window?.rootViewController = vc
class FirstVC: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.title = "first" self.view.backgroundColor = UIColor.red } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { let twoVC = TwoVC(); twoVC.two = "这是给第二个页面传递的参数" twoVC.block = {(message:String)->(Void) in print("FirstVC---------------\(message)") } self.navigationController?.pushViewController(twoVC, animated:true) } }
typealias Block = (_ message:String)->(Void) class TwoVC: UIViewController { var two :String? var block :Block? override func viewDidLoad() { super.viewDidLoad() self.title = "two" self.view.backgroundColor = UIColor.blue print("TwoVC-------\(self.two)") } override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { if((self.block) != nil){ self.block!("这里是给第一个页面传递的参数") } self.navigationController?.popViewController(animated: true) } }
swift找window,导航栏的简单使用,Controller通过闭包传值简单示例
标签:bsp touch sel 导航 message 导航栏 info navig red
原文地址:https://www.cnblogs.com/hualuoshuijia/p/11655712.html