|
|
(同じ利用者による、間の6版が非表示) |
行1: |
行1: |
− | *AppDelegate.swift
| + | [[ios/swift/ナビゲーションバー/コードのみ]] |
− | class AppDelegate: UIResponder, UIApplicationDelegate {
| + | |
− | var window: UIWindow?
| + | |
− | var myNavigationController: UINavigationController?
| + | |
− | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
| + | |
− | let first: ViewController = ViewController()
| + | |
− | myNavigationController = UINavigationController(rootViewController: first)
| + | |
− | self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
| + | |
− | self.window?.rootViewController = myNavigationController
| + | |
− | self.window?.makeKeyAndVisible()
| + | |
− | return true
| + | |
− | }
| + | |
| | | |
− | *ViewController.swift
| + | [[ios/swift/ナビゲーションバー/storyboard]] |
− | class ViewController: UIViewController {
| + | |
− | var addBtn: UIBarButtonItem!
| + | |
− | override func viewDidLoad() {
| + | |
− | super.viewDidLoad()
| + | |
− | self.title = "Home"
| + | |
− | addBtn = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: #selector(ViewController.onClickNavButton))
| + | |
− | self.navigationItem.rightBarButtonItem = addBtn
| + | |
− | }
| + | |
− | func onClickNavButton() {
| + | |
− | let second = SecondViewController()
| + | |
− | self.navigationController?.pushViewController(second, animated: true)
| + | |
− | }
| + | |
| | | |
− | *SecondViewController.swift
| + | [[ios/swift/ナビゲーションバー/色]] |
− | import UIKit
| + | |
− | class SecondViewController: UIViewController {
| + | [[ios/swift/ナビゲーションバー/バー削除]] |
− | override func viewDidLoad() {
| + | |
− | super.viewDidLoad()
| + | [[ios/swift/ナビゲーションバー/右上にボタンを追加]] |
− | self.view.backgroundColor = .redColor()
| + | |
− | self.title = "Second"
| + | |
− | }
| + | |
− | override func didReceiveMemoryWarning() {
| + | |
− | super.didReceiveMemoryWarning()
| + | |
− | }
| + | |
− | }
| + | |