Day 23 XIB跳转页面以及UIAlertController的练习(1/3)

今天我们来练习,XIB的跳页功能跟Alert提示框吧~

首先拉一个Button,按下後提示框跳出,按下OK後跳到下一页。

@IBOutlet var changePageButton: UIButton!

然後拉一个Action,代表按下後会做的事情。

//宣告一个变数,代表第二个页面
let switchToSecondScreen = SecondFrame()

//push过去
 self.navigationController?.pushViewController(switchToSecondScreen, animated: true)

然後我们到档案那边建立第二个画面:

之後拉一个Label,改一下内容。

如果你不想要跳转的时候有这个东东,这个bar可以用这段代码做点击消除

//加在ViewDidLoad下面
self.navigationController?.hidesBarsOnTap = true

然後我们把提示框加进去。

let AlertController = UIAlertController(title: "切换页面?", message: "按下OK後跳转", preferredStyle: .alert) 
    let AlertAction = UIAlertAction(title: "OK", style: .destructive, handler: {action in
        self.navigationController?.pushViewController(switchToSecondScreen, animated: true)
})
        
AlertController.addAction(AlertAction)
        
present(AlertController, animated: true, completion: nil)//提示框弹出
            

我们可以把跳转的功能加到handler,我们在後面加 action in,之後把刚刚的跳转功能加进来复制贴上就可以了~

成果:

明天见拉~


<<:  【设计+切版30天实作】|Day21 - PainPoints - 怎麽切出标题底下的highlight 装饰?

>>:  {DAY 23} Pandas 学习笔记part.9

Day 06 - 那些~帮助开发的套件

如果有错误,欢迎留言指教~ Q_Q classnames: 可以依照逻辑条件的将 classNam...

D3JsDay10 遇到元素资料不相等,用函式解决高人一等

绑定的资料和画面上的元素不相等 enter()函式—没放入元素的资料 先看以下程序码 <bod...

Day29 DOM 介绍

文件物件模型 (DOM) 文件物件模型(DOM)是HTML、XML 和 SVG 文件的程序介面。它提...

Day 30 | 完赛感言

连续30天发文,一开始觉得很漫长,但没想到很快的就来到了尾声! 透过这个比赛,学到了许多东西(虽然听...

D04 / 可不可以用 ConstraintLayout - ConstraintLayout

今天大概会聊到的范围 Constraint Layout in Compose 上一篇提到,有 R...