Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/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
Ios 如何使用Swift从按钮点击警报返回bool_Ios_Swift_Boolean - Fatal编程技术网

Ios 如何使用Swift从按钮点击警报返回bool

Ios 如何使用Swift从按钮点击警报返回bool,ios,swift,boolean,Ios,Swift,Boolean,上面的代码需要在最后一个花括号前返回真/假,但如果这样做,我将丢失返回按钮 那么,有没有办法将其归档 我使用SCLARTERVIEW查看我的警报(如果有人知道如何使用uialert,我希望看到它) 提前感谢。为了添加到第一条注释中,我在标题单元格中使用了UISwitch,并在类的顶部声明了bool变量 override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject!) -> Bool

上面的代码需要在最后一个花括号前返回真/假,但如果这样做,我将丢失返回按钮

那么,有没有办法将其归档

我使用
SCLARTERVIEW
查看我的警报(如果有人知道如何使用uialert,我希望看到它)


提前感谢。

为了添加到第一条注释中,我在标题单元格中使用了UISwitch,并在类的顶部声明了bool变量

 override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject!) -> Bool {
        let appearance = SCLAlertView.SCLAppearance(
            showCloseButton: false,
            showCircularIcon: false
        )
        let alertView = SCLAlertView(appearance: appearance)
        alertView.addButton("First") {
            return true
        }
        alertView.addButton("Second") {
            return false
        }

        alertView.showSuccess("warning", subTitle: "something")


    }
然后在这个方法中设置如下

@IBAction func `switchAction`(_ sender: UISwitch) {
selected = sender.isOn
    if selected == false {
        //do you stuff here change false to true if you need it that way
    }
}

您可以使用block-closesure

override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
    var enable: Bool = false
    if selected == false {
        enable = true
    } else {
        enable = false
    }

    return enable
}
使用它:

 var alertAction :((result:Bool)->())?  
实施:

 alertView.addButton("Second") {
    alertAction?(false)
}  

不要在该方法中使用警报(将有“异步”答案)。在此之前使用它创建一个不同的方法,并根据该值执行以下步骤:用
self.performsgue(…)
@Larme替换
return true
,那么我应该将警报放在
didselect
函数中,然后使用
self.performsgue(…)
?创建一个方法
showarert()
。在
didSelect()
中,调用
showart()
。如果是“First”,请调用
self.performsgue()
。我是否应该从情节提要中删除segue?@MikeVoris是如何在情节提要中连接segue的?谢谢,但我从评论中找到了解决方案。
alertAction = {result in
    // do s.t
}