【发布时间】:2017-01-12 06:17:30
【问题描述】:
我想在NSObject 类中为UIAlertCotroller 创建一个函数。这样我就可以在任何类中访问此功能。我已尝试使用以下代码:
open class func showActionSheet(_ delegate: UIViewController, message: String, strtittle: String, handler: ((UIAlertController) -> Void)! = nil)
{
let actionSheetController: UIAlertController = UIAlertController(title: strtittle, message: message, preferredStyle: UIAlertControllerStyle.actionSheet)
if handler == nil{
actionSheetController.addAction(UIAlertAction(title: "Default(Off)" , style: .default , handler:{ (UIAlertAction)in
}))
}
else{
actionSheetController.addAction(UIAlertAction(title: "Default(Off)" , style: .default , handler:{ (UIAlertAction)in
}))
}
delegate.present(actionSheetController, animated: true, completion: {
print("completion block")
})
}
这是我制作的函数,但问题是 ActionSheet 中可以有多个动作,它们也有不同的标题和不同的样式。
问题:如何实现这个功能?请帮忙。
谢谢!
【问题讨论】:
-
谢谢您,我认为这仅适用于 AlertController(警报类型)。我正在寻找 AlertController(Action sheet)。
-
你只需要改变它,这就是为什么我写你可以这样尝试。您也可以为动作标题添加一个字符串数组参数。
-
这是否意味着我必须知道最大操作数?
-
类似
func buildAlertInfoWithFavButton(withTitle title: String?, andMessage message: String?, withActionTitles titles:[String], withHandler handler: [((UIAlertAction) -> Void)]?) -> UIAlertController {传递动作标题数组。
标签: ios swift3 uialertcontroller uiactionsheet