ios - 在 Swift 中将多个参数传递给 UIAlertAction
问题描述
我一直在尝试找到一种将多个参数传递给 UIAlertAction 的方法。以下是我的代码。我想将“源”字符串传递给警报的 joinSelected 操作。
我收到这样的错误:
无法将类型“()”的值转换为预期的参数类型“((UIAlertAction)->
fileprivate func showBetaAlert(source: String) {
let betaAlert = UIAlertController.betaProgramAlert()
let joinAction = UIAlertAction(title: "Join", style: UIAlertActionStyle.default, handler: joinSelected(alert: <#UIAlertAction#>, source: source))
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: cancelSelected)
betaAlert.addAction(cancelAction)
betaAlert.addAction(joinAction)
present(betaAlert, animated: true, completion: nil)
}
fileprivate func joinSelected(alert: UIAlertAction, source: String) {
let betaAlert = UIAlertController.signUpAlert()
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: dismissEmailAction)
let submitAction = UIAlertAction(title: "Submit", style: .default , handler: { [weak self] _ in
guard let stelf = self else { return }
let email = betaAlert.textFields![0] as UITextField
stelf.submitAction(email: email.text!)
})
betaAlert.addAction(cancelAction)
betaAlert.addAction(submitAction)
present(betaAlert, animated: true, completion: nil)
}
解决方案
替换这一行:
let joinAction = UIAlertAction(title: "Join", style: UIAlertActionStyle.default, handler: joinSelected(alert: <#UIAlertAction#>, source: source))
和:
let joinAction = UIAlertAction(title: "Join", style: UIAlertActionStyle.default, handler: { [weak self] _ in
joinSelected(source: source)
})
并更新joinSelected
为:
fileprivate func joinSelected(source: String) {
推荐阅读
- c - 具有不同结构的分段错误
- java - 如何在java中获取所需日期的日期对象?
- r - R:通过索引删除数据框中的行
- r - 在 dplyr::mutate() 中编写一个具有默认列名输入的函数
- javascript - 如何使用 innerHTML 将结果打印到 div 标签中
- database - 我可以通过数据库链接编译大型存储过程吗?
- javascript - puppeteer 如何从窗口范围获取变量
- qgis - QGIS - 无法更改 shapefile 的 CRS
- recursion - 递归函数中的多项选择
- ios - 在我的自定义 collectionView 布局中未调用 prepare()