2015-07-10 58 views
-1

如何从UIAlertAction内引用selfSwift:单击更改UIAlertAction标题

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

我想让UIAlertAction的标题在点击时(以及其他事物)发生变化。如何在命令中引用我自己在点击时做什么?

我如何让它在那里点击一个UIAlertAction如果您想从自己的处理程序访问UIAlertAction对象不关闭警报操作

+0

当点击按钮时,您无法防止'UIAlertController'解除关闭。 – rmaddy

回答

1

,只需使用提供action参数传递给操作处理程序块。

但是,由于title参数是只读的,所以无法更改操作的标题。

但是,无论如何,甚至没有理由甚至改变标题,因为在点击任何警报动作按钮时警报总是被解散。

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" 
    })) 
}