ios - 更改按钮的标题

标签 ios swift uialertcontroller uialertaction

我有一个 alertController ,其中有一个 button 。以下是我创建按钮的方法:

var myButton : UIAlertAction!

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

选择按钮后,我想在标题的开头添加一个“✔︎”。 (正如您在上面的最后一行代码中看到的。)当我尝试这样做时,出现以下错误:

Cannot assign to the result of this expression

我可以做什么来解决这个问题?如果 myButtons 标题是只读,那么是否有有效的解决方法?

最佳答案

该错误与“✔︎”无关。这是因为 myButton。将 UIAlertAction 分配给 String 没有任何意义。这就是您得到错误的方式。

关于ios - 更改按钮的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32341511/

相关文章:

ios - 获取排序记录的问题 (CoreData)

c# - 在 monoTouch 中格式化大量数据

ios - 符合 Equatable for Diffing 的协议(protocol)

ios - 如何让1个IBOutlet适用于不同的设备?

ios - 如何在 Skscene 中呈现 UIAlert

ios - Swift 4 UIAlertController 如何将不同的操作组合到 1 个完成处理程序中?

ios - Objective-C:2个iPad之间的通信

ios - SLComposeServiceViewController高度问题

swift - 二元运算符 '===' 不能应用于类型 'Any?' 和 'UIBarButtonItem!' 的操作数

ios - 如何将图像放在 UIActionSheet 上?