建立项目,拖拉拽如下:

页面1 ViewController.swift 中代码如下:
//
// ViewController.swift
// Nav
//
// Created by Wanghui on 2018/12/24.
// Copyright © 2018 Wanghui. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func test(_ sender: Any) {
print("testBtn")
self.performSegue(withIdentifier: "login", sender: self)
}
//重写这个方法 准备跳转时候调用
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "my01"{
let controller = segue.destination as! MyViewController
controller.deviceUdid = "wanghui"
}
else if(segue.identifier == "login")
{
let controller = segue.destination as! MyViewController
controller.deviceUdid = "Hello,World!"
}
}
}
接受页面 MyViewController.swift 代码如下:
// MyViewController.swift
// Nav
//
// Created by Wanghui on 2018/12/24.
// Copyright © 2018 Wanghui. All rights reserved.
//
import UIKit
class MyViewController: UIViewController {
var deviceUdid:String = "" ;
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
print("得到了消息!:\(deviceUdid)")
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
调试结果如下:
testBtn
得到了消息!:Hello,World!
网友评论