Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何使用;“处理者”;是否调用另一个UIAlertAction?_Swift - Fatal编程技术网

Swift 如何使用;“处理者”;是否调用另一个UIAlertAction?

Swift 如何使用;“处理者”;是否调用另一个UIAlertAction?,swift,Swift,是否可以使用处理程序触发其他警报 func jokeFinal() { let alert = UIAlertController(title: "Never Mind", message: "It's Pointless", preferredStyle: .alert) let action = UIAlertAction(title: "Hahahahahaha", style: .default, handler: nil) alert.addAction(act

是否可以使用处理程序触发其他警报

func jokeFinal() {
    let alert = UIAlertController(title: "Never Mind", message: "It's Pointless", preferredStyle: .alert)
    let action = UIAlertAction(title: "Hahahahahaha", style: .default, handler: nil)
    alert.addAction(action)
    present(alert, animated: true, completion: nil)
}

func joke() {
    let alert = UIAlertController(title: "A broken pencil", message: "...", preferredStyle: .alert)
    let action = UIAlertAction(title: "A broken pencil who?", style: .default, handler: jokeFinal())
    alert.addAction(action)
    present(alert, animated: true, completion: nil)
}

@IBAction func nock() {
    let alert = UIAlertController(title: "Knock,Knock", message: "..", preferredStyle: .alert)
    let action = UIAlertAction(title: "Who's there??", style: .default, handler: joke())
    alert.addAction(action)
    present(alert, animated: true, completion: nil)
}
我正在尝试使用
UIAlertAction
的处理程序调用另一个
UIAlert
。可能吗

我收到以下错误:

无法将类型“()”的值转换为所需的参数类型“((UIAlertAction)->Void)?”

处理程序不调用函数。这是一个函数

例如,你可以这样做。更改

 func jokeFinal() {

然后改变

 handler: jokeFinal()

依此类推。

处理程序不调用函数。这是一个函数

例如,你可以这样做。更改

 func jokeFinal() {

然后改变

 handler: jokeFinal()


等等。

当然可以!这是可能的。试试这样:

let alertController = UIAlertController.init(title: "Title", message: "Message", preferredStyle: .alert)
alertController.addAction(UIAlertAction.init(title: "Title", style: .default, handler: { (action) in
        self.someFunction()
}))
self.present(alertController, animated: true, completion: nil)
以下是您的功能:

func someFunction() {
    let alertController = UIAlertController.init(title: "Some Title", message: "Some Message", preferredStyle: .alert)
    alertController.addAction(UIAlertAction.init(title: "Title For Button", style: .default, handler: { (action) in
        // Completion block
    }))
    self.present(alertController, animated: true, completion: nil)
}
以下是您的问题:

let action = UIAlertAction(title: "Who's there??", style: .default, handler: joke())
您可以轻松地将其更改为:

let action = UIAlertAction(title: "Who's there??", style: .default, handler: { (action) in
        // Completion block
})

希望有帮助

当然可以!这是可能的。试试这样:

let alertController = UIAlertController.init(title: "Title", message: "Message", preferredStyle: .alert)
alertController.addAction(UIAlertAction.init(title: "Title", style: .default, handler: { (action) in
        self.someFunction()
}))
self.present(alertController, animated: true, completion: nil)
以下是您的功能:

func someFunction() {
    let alertController = UIAlertController.init(title: "Some Title", message: "Some Message", preferredStyle: .alert)
    alertController.addAction(UIAlertAction.init(title: "Title For Button", style: .default, handler: { (action) in
        // Completion block
    }))
    self.present(alertController, animated: true, completion: nil)
}
以下是您的问题:

let action = UIAlertAction(title: "Who's there??", style: .default, handler: joke())
您可以轻松地将其更改为:

let action = UIAlertAction(title: "Who's there??", style: .default, handler: { (action) in
        // Completion block
})
希望有帮助