//最初の画面のコード
import UIKit
class ViewController: UIViewController {
let navBar = UINavigationBar(frame : CGRect(x: 0, y: 40, width: UIScreen.main.bounds.size.width, height: 100 ))
let navItem : UINavigationItem = UINavigationItem(title: "タイトル")
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.gray
navItem.rightBarButtonItem = UIBarButtonItem(title: "遷移", style: UIBarButtonItem.Style.plain, target: self, action:#selector(self.rightHandAction))
navBar.pushItem(navItem, animated: true)
self.view.addSubview(navBar)
//画面遷移する関数
@objc func rightHandAction(_ sender: UIBarButtonItem) {
print("right bar button action")
let vcC : UIViewController = viewControllerConfig()
let naviVC : UINavigationController = UINavigationController(rootViewController: vcC)
self.navigationController?.pushViewController(naviVC,animated: true)
}
}
//最初の画面のコード
import UIKit
class ViewController: UIViewController {
let navBar = UINavigationBar(frame : CGRect(x: 0, y: 40, width: UIScreen.main.bounds.size.width, height: 100 ))
let navItem : UINavigationItem = UINavigationItem(title: "タイトル")
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.gray
navItem.rightBarButtonItem = UIBarButtonItem(title: "遷移", style: UIBarButtonItem.Style.plain, target: self, action:#selector(self.rightHandAction))
navBar.pushItem(navItem, animated: true)
self.view.addSubview(navBar)
//画面遷移する関数
@objc func rightHandAction(_ sender: UIBarButtonItem) {
print("right bar button action")
let vcC : UIViewController = viewControllerConfig()
let naviVC : UINavigationController = UINavigationController(rootViewController: vcC)
self.navigationController?.pushViewController(naviVC,animated: true)
}
}
//遷移先の画面のコード
import UIKit
class viewControllerConfig: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Config"
self.view.backgroundColor = UIColor.cyan
}
}
//遷移先の画面のコード
import UIKit
class viewControllerConfig: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.title = "Config"
self.view.backgroundColor = UIColor.cyan
}
}