-1

如何self从 UIAlertAction 中引用?

refreshAlert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { (action: UIAlertAction!) in
        // self.title = String("HELLO")
        print("Handle Ok logic here")
    }))

我希望 UIAlertAction 的标题在单击时更改(以及其他内容)。如何在命令中引用自己单击时要执行的操作?

如何使它在单击 UIAlertAction 时不会关闭警报操作

4

2 回答 2

1

如果您想UIAlertAction从其自己的处理程序访问对象,只需使用action传递给操作处理程序块的提供的参数。

title但是,由于该参数是只读的,因此您无法在创建操作后更改它的标题。

此外,无论如何,几乎没有理由更改标题,因为在点击任何警报操作的按钮时总是会解除警报。

于 2015-07-10T00:29:13.310 回答
0

UIAlertController 的 title 属性是只读的。你不能分配任何东西。但是,您可以处理它以使用此代码。

var propTitle:String = "BYE" // it's property of class

func method(){
    refreshAlert.addAction(UIAlertAction(title: propTitle, style: .Default, handler: { (action: UIAlertAction!) in
        self.propTitle = "HELLO"
    }))
}
于 2016-09-27T03:30:27.590 回答