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
}