- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 swift 和 IOS 开发总体来说是新手,所以我在 Xcode 中制作了一个操作表,但现在我想从操作表中执行操作。我熟悉在 ObjC 中使用按钮 Index 执行此操作,但我似乎无法在 swift 中弄清楚这一点。
我还想自定义我的操作表以使文本具有不同的颜色,但这并不那么重要。如果你能帮忙,请告诉我。谢谢
这是到目前为止我的代码,但按下按钮时操作的 .tag 部分是错误的......
@IBAction func ActionSheet(sender: UIButton) {
var sheet: UIActionSheet = UIActionSheet();
let title: String = "Action Sheet!";
sheet.title = title;
sheet.addButtonWithTitle("Cancel");
sheet.addButtonWithTitle("A course");
sheet.addButtonWithTitle("B course");
sheet.addButtonWithTitle("C course");
sheet.cancelButtonIndex = 0;
sheet.showInView(self.view);
}
func actionSheet(sheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int) {
if (actionSheet.tag == 1) {
NameLabel.text = "I am confused"
}
}
最佳答案
你需要:
使您的 View Controller 符合 UIActionSheetDelegate
协议(protocol):
ViewController 类:UIViewController、UIActionSheetDelegate {
添加self
作为委托(delegate),并将标签设置为1:
var sheet: UIActionSheet = UIActionSheet()
let title: String = "Action Sheet!"
sheet.title = title
sheet.addButtonWithTitle("Cancel")
sheet.addButtonWithTitle("A course")
sheet.addButtonWithTitle("B course")
sheet.addButtonWithTitle("C course")
sheet.cancelButtonIndex = 0
sheet.delegate = self // new line here
sheet.tag = 1 // another new line here
sheet.showInView(self.view)
现在您可以使用buttonIndex
:
func actionSheet(sheet: UIActionSheet!, clickedButtonAtIndex buttonIndex: Int) {
if sheet.tag == 1 {
println(buttonIndex)
println(sheet.buttonTitleAtIndex(buttonIndex))
}
}
关于ios - Swift 中的 ActionSheet 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26318359/
我需要在 ActionSheet 中生成按钮的动态列表.假设我有一系列选项 ["Option1", "Option2"] ,我怎样才能做到这一点? .actionSheet(isPresented:
我有以下示例代码: import SwiftUI struct ContentView: View { var body: some View { NavigationView
如何导航出ActionSheet在那里我只能通过 Text但不是 NavigationLink ? 示例代码: struct DemoActionSheetNavi: View { @Stat
针对这三个语句获取三个警告消息 ActionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque; [ActionSheet showInVie
我有一个方法可以抛出一个由数组填充的 actionSheet。 问题是,一旦我将该方法放入 1 个按钮的发送器中,每次 按钮按下时它都会触发。 我只希望它显示一个按钮 (btnPortfolio)。
我正在使用 Action Sheet Picket .我按照自述文件、选择器中的说明添加了 .h 和 .m 文件,甚至 cancelAction 运行良好,但不知何故 successAction 抛出
我有一个棋盘游戏,我正在使用操作表来撤消移动。我能够撤消移动并将该片段从当前位置动画化到之前的位置。 但由于空间较小,我使用操作表供用户选择撤消选项。 但问题是当用户选择撤消时,动画会在操作表消失之前
我有 ActionSheet 的代码,它可以连接的东西有点慢? @IBAction func showAction(_ sender: UIButton) { let actionSheetC
我有这段代码可以从 NSMutableArray 的 NSDictionary 获取 NSStrings,但问题是它显示不正确。这是代码: UIActionSheet *playingSheet =
我正在尝试获取我的数组 sizes(可以有不同的值)。我正在尝试遍历数组并在 ActionSheet 中创建一个 .default 按钮。 代码如下: var sizes = ["S", "M", "
当在 View 中的任何点显示 actionSheet 时,它会显示一个方向向下的箭头(在 actionsheet 下方),即使 actionSheet 在 View 中有足够的空间来显示“向上”箭头
我正在尝试获取我的数组 sizes(可以有不同的值)。我正在尝试遍历数组并在 ActionSheet 中创建一个 .default 按钮。 代码如下: var sizes = ["S", "M", "
自 iOS 13 以来,我的带有 actionSheet 样式的警报显示为“延迟”标题和消息。 这些是 Apple 的 release notes . 我已经研究了很多,但找不到如何让它像 iOS 1
我的问题是我有一个 ActionSheet,仅当此按钮下的操作完成时,它才会从屏幕上消失。我的问题是我想在我的操作表中单击“保存”,然后关闭操作表,然后显示一些警报,通知用户等待保存完成。目前它的工作
我希望有人可以帮助我...我想在我正在开发的 iPad 应用程序中使用弹出窗口(或显示为弹出窗口的操作表)。 我遇到的问题是让它们看起来像我想要的那样。我希望我的弹出窗口看起来像许多核心应用程序中使用
我是 iOS 开发的新手,遇到了一个我似乎无法找到解决方案的错误。我到处寻找解决方案,但也许是我的新奇阻碍了我看到问题。 日志中打印的确切警告是: 在演示或关闭正在进行时尝试从 View Contro
我目前尝试使用 2 个操作表(或可能更多)并希望对它们进行不同的操作。 @IBAction func BTActionSheet(sender: AnyObject) { let a
我想将图像放在 ActionSheet 的右侧,就像在 AppStore 上看到的那样。我知道如何添加图像并更改 titleText 样式,但我无法弄清楚如何更改这两者的位置。 第三方库不受欢迎。 屏
我在我的 iOS 应用程序中使用 UIAlertController;但是,为了节省重复的代码行,我想在 if/else 分支之前初始化 UIAlertController。即 var alertCo
我希望其中一个选项在单击时不执行任何操作。它基本上是一个占位符。它没有标题,只有白色。 func actionSheet(sheet: UIActionSheet, clickedButtonAtIn
我是一名优秀的程序员,十分优秀!