IOS(Swift)

pushViewController popViewController

----___<<<<< 2021. 5. 6. 23:01

 

class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "PUSH"
let push = UIButton(frame: CGRect(x: 0, y: 0, width: 150, height: 50))
push.setTitle("push noti", for: .normal)
push.setTitleColor(.red, for: .normal)
push.center = view.center
push.addTarget(self, action: #selector(clickPush), for: .touchUpInside)
view.addSubview(push)
}
@objc func clickPush(){
print("ttt")
let secondVC = SecondViewController()
self.navigationController?.pushViewController(secondVC, animated: true)
}
}
class SecondViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("second")
let pop = UIButton(frame: CGRect(x: 0, y: 0, width: 150, height: 50))
pop.setTitle("push noti", for: .normal)
pop.setTitleColor(.red, for: .normal)
pop.center = view.center
pop.addTarget(self, action: #selector(clickPop), for: .touchUpInside)
view.addSubview(pop)
}
@objc func clickPop(){
print("ttt")
let secondVC = SecondViewController()
navigationController?.popViewController(animated: true)
}
}

 

'IOS(Swift)' 카테고리의 다른 글

Swift costom dialog  (0) 2021.05.07
Swift Rating bar  (0) 2021.05.07
Segue data model 전달  (0) 2021.04.30
Segue Type  (0) 2021.04.28
Swift Mutating  (0) 2021.04.21