//第一个界面ViewController
import UIKit
class ViewController: UIViewController {
fileprivate var tf:UITextField = UITextField()
override func viewDidLoad() {
super.viewDidLoad()
setUpUI()
}
//点击进入第二个界面的按钮进行跳转操作
@objc fileprivate func btnAction() {
let vc = DetailViewController()
navigationController?.pushViewController(vc, animated: true)
}
}
//设置界面
extension ViewController{
fileprivate func setUpUI() {
let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
btn.center = self.view.center
btn.backgroundColor = UIColor.cyan
btn.addTarget(self, action: #selector(btnAction), for: .touchUpInside)
btn.setTitle("进第二个界面", for: UIControlState.normal)
self.view .addSubview(btn)
tf = UITextField(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
tf.center = self.view.center
tf.frame.origin.y = 200
tf.backgroundColor = UIColor.blue
self.view.addSubview(tf)
}
}
//第二个界面DetailViewController
import UIKit
class DetailViewController: UIViewController {
var tf:UITextField!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.white
setUpUI()
}
//点击按钮返回上一界面
func btnAction() {
navigationController?.popViewController(animated: true)
}
extension DetailViewController{
fileprivate func setUpUI() {
let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 30))
btn.center = self.view.center
btn.backgroundColor = UIColor.cyan
btn