首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在UIAlertAction中返回int或在UIAlertAction之后返回int

在UIAlertAction中返回int或在UIAlertAction之后返回int
EN

Stack Overflow用户
提问于 2015-08-03 17:12:24
回答 1查看 566关注 0票数 1

我想在UIAlertAction中返回一个整数。现在,我得到了一个错误:“Int不可转换为Void.‘”。警报所在的函数应该返回int。

这是我的代码:

代码语言:javascript
复制
func writeSteps() -> Int {
    var allergies = 0

    var severe = UIAlertController(title: "More information", message: "blablabla", preferredStyle: UIAlertControllerStyle.Alert)

    severe.addAction(UIAlertAction(title: "Yes", style: .Default, handler: { (action: UIAlertAction!) in

         allergies += 1
         return allergies


    }))

    severe.addAction(UIAlertAction(title: "No", style: .Default, handler: { (action: UIAlertAction!) in
         allergies += 2
         return allergies

    }))
    self.presentViewController(severe, animated: true, completion: nil)
}

这个是可能的吗?

如果不是,每当我试图在uiAlertController之后返回某项内容时,它首先返回该值,然后出现ui警报。是否有一种方法可以先发出警告,然后返回变量?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-03 17:44:13

如果您只是试图更新allergies中的值,则可以保留对要更新的属性(self.allergies)的引用,然后可以在操作中增加该属性。

如果需要返回此值,可以在处理程序中调用第二个方法:

代码语言:javascript
复制
severe.addAction(UIAlertAction(title: "No", style: .Default, handler: { (action: UIAlertAction!) in
     self.returnAllergiesWithVal(2);
}))

然后,returnAllergiesWithVal方法可以将该值传递到需要它的任何地方。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31793030

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档