gpt4 book ai didi

swift - 单击后如何使用 Swift 在 iOS 中启用 Uialertview 特定按钮?

转载 作者:行者123 更新时间:2023-11-28 14:53:38 27 4
gpt4 key购买 nike

enter image description here

关于按钮清除历史我想启用其他 2 个按钮。我是 iOS 新手。

let alert = UIAlertController(title: "Title", message: nil, preferredStyle: .actionSheet)

alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
let markAction = UIAlertAction(title: "Mark as Urgent", style: .default, handler: { (action) in

})
let resolveAction = UIAlertAction(title: "Resolvethe conversion", style: .default, handler: { (action) in

})
markAction.isEnabled = false
resolveAction.isEnabled = false
alert.addAction(markAction)
alert.addAction(UIAlertAction(title: "Clear history", style: .default, handler: { (action) in
alert.actions.map {$0.isEnabled = true}
}))
self.present(alert, animated: true, completion: nil)
}

最佳答案

您可以在清除按钮完成处理程序中启用您的操作并再次显示您的警报,因为您无法避免关闭:

let alert = UIAlertController(title: "Title", message: nil, preferredStyle: .actionSheet)
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
let markAction = UIAlertAction(title: "Mark as Urgent", style: .default, handler: { (action) in

// TODO: Your action

})

markAction.isEnabled = false
alert.addAction(markAction)
alert.addAction(UIAlertAction(title: "Clear history", style: .default, handler: { (action) in
alert.actions.map {$0.isEnabled = true}
self.present(alert, animated: true, completion: nil)
}))

self.present(alert, animated: true, completion: nil)

关于swift - 单击后如何使用 Swift 在 iOS 中启用 Uialertview 特定按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49587032/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com