This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
var pageA: PageA? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
window = UIWindow(frame: UIScreen.main.bounds) | |
pageA = PageA() | |
let nav: UINavigationController = UINavigationController(rootViewController: pageA!) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.navigationItem.title = "PageA" | |
self.view.backgroundColor = UIColor.white | |
// 生成切換至PageB的按鈕 | |
let switchBtn: UIButton = UIButton() | |
switchBtn.frame = CGRect(x: self.view.frame.size.width / 2 - 100, y: self.view.frame.size.height / 2 - 25, width: 200, height: 50) | |
switchBtn.titleLabel?.font = UIFont.systemFont(ofSize: 30) | |
switchBtn.setTitle("切換至PageB", for: .normal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PageB: UIViewController, UITableViewDelegate, UITableViewDataSource { | |
var delegate: PageBDelegate! // delegate | |
var testDataTV: UITableView! | |
var dataList: [String] = ["Apple", "Banana", "Cherry"] // 畫面上顯示的資料 | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.navigationItem.title = "PageB" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 切換至PageB | |
func onClickToPageB(_ sender: UIButton) { | |
let pageB: PageB = PageB() | |
pageB.delegate = self // 由我(PageA)來代理你(PageB) | |
self.navigationController?.pushViewController(pageB, animated: true) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Shape { | |
case rectangle | |
case circle | |
case other | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Shape: Int { | |
case rectangle = 1 | |
case circle = 2 | |
case other = 3 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Shape { | |
case rectangle(Int) | |
case circle(Int, Int) | |
case other | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Shape: Int { | |
case rectangle = 1 | |
case circle = 2 | |
case other = 3 | |
} | |
func chooseShape(shape: Shape) { | |
switch shape { | |
case .rectangle: | |
print("長方形...") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Shape { | |
case rectangle(Int, Int) | |
case circle(Double) | |
case other | |
} | |
func chooseShape(shape: Shape) { | |
switch shape { | |
case .rectangle(let width, let height): | |
print("長方形的面積為: \(width * height)") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Shape: Int { | |
case rectangle = 1 | |
case circle = 2 | |
case other = 3 | |
} | |
func chooseShape(shape: Shape) { | |
switch shape { | |
case .rectangle: | |
print("長方形") |