栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Swift的子视图类中创建警报?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Swift的子视图类中创建警报?

有几种方法可以使

UIViewController
您抓住自己的生活
UIView

  1. 您可以将任何视图控制器作为 委托 来显示警报;
  2. 您可以将视图控制器的 引用 传递给您的视图;和
  3. 通常,您始终
    rootViewController
    可以在代码中的任何位置进行抓取。

dismissViewControllerAnimated(_: completion:)
当您以后想要关闭警报时,需要在同一视图控制器上调用。

因此,我将针对您的情况做一个如此快速的解决方案:

func move() {    if !gameBoard.checkNextMoveExist() {        let rootViewController: UIViewController = UIApplication.sharedApplication().windows[0].rootViewController        var alert = UIalertController(title: "Game Over", message: nil, preferredStyle: UIalertControllerStyle.alert)        alert.addAction(UIalertAction(title: "Take Me Back", style: UIalertActionStyle.Cancel, handler: {(action: UIalertAction!) in rootViewController.dismissViewControllerAnimated(true, completion: nil) println("Taking user back to the game without restarting")        }))        alert.addAction(UIalertAction(title: "New Game", style: UIalertActionStyle.Destructive, handler: {(action: UIalertAction!) in rootViewController.dismissViewControllerAnimated(true, completion: nil) println("Starting a new game") self.restartGame()        }))        rootViewController.presentViewController(alert, animated: true, completion: nil)    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/381637.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号