刻好画面後,在 ViewController.swift ( MainVC.swift ) 加入「 利用 push 转画面 」的程序码
在专案底下 New Group / New File / 选 Cocoa Touch Class
在 SecondVC.xib 里新增一个 Lable ,当在 MainVC 按下 Button 後,即可辨别是否跳页成功;在 SecondVC 按下 Button 後即可跳回 MainVC 。
在 SecondVC.swift 加入跳回 MainVC 的程序码
在 ViewController.swift ( MainVC.swift ) 加入「 利用 present 转画面 」的程序码
在 SecondVC.swift 加入跳回 MainVC 的程序码
附上完整程序码
// MainVC.swift
import UIKit
class MainVC: UIViewController {
@IBOutlet weak var btn: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.hidesBarsOnTap = true
}
// MARK: - push
@IBAction func btnAct1(_ sender: UIButton) {
let toSecondVC = SecondVC()
self.navigationController?.pushViewController(toSecondVC, animated: true)
}
// MARK: - present
@IBAction func btnAct2(_ sender: UIButton) {
self.present(SecondVC(), animated: true, completion: nil)
}
}
// SecondVC.swift
import UIKit
class SecondVC: UIViewController {
@IBOutlet weak var btnToMainVC: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - push
@IBAction func btnPush(_ sender: UIButton) {
self.navigationController?.popViewController(animated: true)
}
// MARK: - present
@IBAction func btnPresent(_ sender: UIButton) {
self.dismiss(animated: true, completion: nil)
}
}
这样就完成 push 、 present 转画面啦!明天会介绍 Protocol And Delegate,敬请期待!
<<: Day 29. Hashicorp Consul: Upgrade
问题回答 递回元件是指同一个元件里不断引用自己,造成重复一层元件包着一层元件的情况,直至该元件所渲染...
回圈结构是高阶语言其中一项重要的发展,回圈事实上结合了低阶语言的部分功能,使得程序部分的叙述区块能够...
CSS isolation 介绍 有时候会想对不同 Component 做个别样式设定,但如果把 c...
这是一篇有用的工具文。 日常生活中,我们不可避免会碰上误删,误格式化硬碟/外接硬碟/记忆卡亦或是随身...
来到2048的最後一天!看看这麽多的删除线!虽然可能我们不一定能清光我们购物网站上的愿望清单,但是今...