Change title of button

时间:2015-09-01 21:55:24

标签: ios swift uialertcontroller uialertaction

I have an alertController with a button in it. Here's how I created the button:

var myButton : UIAlertAction!

// Later...
self.myButton = UIAlertAction(title: "myButton", style: .Default, handler: {action -> Void in
   self.myButton.title = "✔︎\(myButton)"
})

After the button get's selected, I want to add a "✔︎" at the beginning of the title. (As you can see in the last line of code above.) When I try doing that, I get the following error:

Cannot assign to the result of this expression

What can I do to fix that? If myButtons title is read-only, then is there a valid workaround to it?

1 个答案:

答案 0 :(得分:0)

The error is not about the "✔︎". It's because of myButton. It means nothing to assign a UIAlertAction to String. That's how you get the error.