- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个包含 subview 的 View Controller 。在 subview 类中,我可能需要在满足某些条件时弹出警报。
class GameViewController: UIViewController {
@IBOutlet var gameBoardUIView: GameBoardUIView
...
}
class GameBoardUIView: UIView {
...
func move() {
if !gameBoard.checkNextMoveExist() {
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
println("Taking user back to the game without restarting")
}))
alert.addAction(UIAlertAction(title: "New Game", style: UIAlertActionStyle.Destructive, handler: {(action: UIAlertAction!) in
println("Starting a new game")
self.restartGame()
}))
// This is where the question is
// self.presentViewController(alert, animated: true, completion: nil)
}
}
}
从代码中可以看出,我无法调用 presentViewController 函数来显示警报,因为我的 subview 不是 Controller 类。我应该以某种方式在 subview 中创建对父 Controller 的周引用吗?实现此类引用的最佳做法是什么?
最佳答案
swift 4
只需在 Root View Controller 的 UIApplication 窗口中显示警报:
let title = "Some title"
let message = "body message"
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
let action = UIAlertAction(title: "Aceptar", style: .cancel, handler: nil)
alert.addAction(action)
UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil)
关于ios - 如何在 Swift 的 subview 类中创建警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24584364/
我正在尝试将字符串转换为 float 。我知道 parseFloat() 可以做到这一点,但我也找到了下面的语法,但没有太多引用。 什么是正确的语法,因为它们似乎都有效。我可以在哪里了解更多相关信息?
我见过一些看起来很酷的“窗口”/“警报”/不管它们叫什么。我希望我知道。以下是其中的一些示例: 这些不应该是 Apple 独有的,因为我已经看到 3rd 方应用程序使用它们!我想知道这些 window
这个问题已经有答案了: What is the difference between a function call and function reference? (6 个回答) 已关闭 7 年前。
alert('test1'); var re = new RegExp("(http://(?:[A-Za-z0-9-]+\\.)?[A-Za-z0-9-]+\\.[A-Za-z0-9-]+/?)",
我有一个 Rails 应用程序,它与其他 Rails 应用程序通信以进行数据插入。我使用 jQuery $.post 方法进行数据插入。对于插入,我的其他 Rails 应用程序显示 200 OK。但在
我的作业有问题...我不知道我的代码有什么问题..我的作业是创建一个简单的学习数学和级别选择......我使用下拉菜单来选择级别和算术运算......现在我的问题是,当我单击按钮时,它将转到函数sta
我有一些复选框,其值属性来自数据库。我希望用户始终检查具有相同值的复选框(如果他不使用 javascript 发出警报)。我尝试使用以下 javascript 代码执行此操作,但没有用 fu
这有点难以解释,我的网站上有一个幻灯片形式的多部分表单。他们必须使用单选按钮从 3/4 选项中进行选择。 我对它们进行了一些验证,以确保用户在允许转到下一张幻灯片之前选择一个。 如果我单击一个对象来选
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 5 年前。 Improve this ques
我的页面上有一个click链接,我想在单击时播放通知或提示音。我如何使用jQuery做到这一点? 在此先感谢... :) 炸药 最佳答案 使用 jQuery sound 插件。 关于javascrip
我正在尝试在 Excel 列中创建 VBA -Alert 弹出窗口。在基于某些计算的 Excel 工作表中,将计算一些增长%(H 列),如果增长%> 20%,则会生成一个警报弹出窗口,询问原因代码,需
当用户滚动到网页的特定部分时,如何使用 JavaScript 显示警报。我尝试通过检查 document.body.clientWidth = document.documentElement.cli
我正在尝试制作一个脚本,其中会弹出一个提示窗口询问问题,并根据其中的答案,会弹出一个警告框,指出答案有效或无效。在我的代码中,我的提示框有效,但我的警报框没有。有人可以帮我解决这个问题吗?非常感谢!!
我正在尝试 Grafana 的警报和通知功能,它看起来真的很棒。 松弛通知示例。 但是有一个大问题。它需要使用 S3 进行配置,这使得任何人都可以公开访问图像。对于那些不希望公开访问其图像的公司来说,
我想知道是否有任何方法可以在 adobe reader 中通知用户pdf 表单已提交到服务器?我正在提交一个正常的 http/html 形式到 php 脚本没什么大不了的,直接,但文档、论坛等似乎存在
在 TFS 中构建失败后,是否可以通过电子邮件获取构建成功的信息? 当构建失败时(我确实如此),我可以收到电子邮件。当构建成功时,我可以收到电子邮件。 但我需要知道构建不再失败。如果我收到构建失败的电
我需要一些帮助来理解 jQuery 如何存储元素。请看一下这个链接: http://jsfiddle.net/NubWC/ 我试图从所有具有特定类的标题标签中获取元素 id,并将其放入数组中,以便我可
我想做 alert(this) 来进行演示(想看看代码中不同位置的“this”是什么)。 有什么想法可以实现这一目标吗? 现在它只返回[object Object]? 最佳答案 这样做: consol
当出现警告框时,有什么方法可以阻止 Enter 键盘吗?因此用户需要按 Esc 键或单击 Ok 按钮来删除警报。 alert('Hello'); 最佳答案 正如我之前的评论所述,标准的 javas
我正在尝试在 javascript 中创建一个函数并传入参数“name”,然后当用户点击一张照片时,会出现一条警告,类似于“这张照片是在 ____ 拍摄的” function photoWhere
我是一名优秀的程序员,十分优秀!