ios - 使用 UIButton 文本作为文本输入 - Swift

标签 ios swift uibutton

你好,我有一个如下所示的 profilelbl 变量,它是一个 uibutton。我希望按钮的文本成为我的数据库中的输入(解析)。但我想不通。我尝试了很多东西,但仍然出现错误:

  @IBOutlet weak var profileLbl: UIButton!

  var notification = PFObject(className: "notifications")

        notification["actionReceiverName"] = profilelbl.text /*not working*/

     /*    also tried

   notification["actionReceiverName"] = sender.profilelbl.text

   notification["actionReceiverName"] = profilelbl.title    */

最佳答案

你可以轻松做到这一点

if let button = profilelbl as? UIButton {
    if let title = button.titleForState(.Normal) {
        println(title)
        notification["actionReceiverName"] = title
    }
}

关于ios - 使用 UIButton 文本作为文本输入 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30936933/

相关文章:

ios - 当应用程序状态暂停时,是否有任何功能可以从多任务栏中查找应用程序何时被杀死?

ios - UITableView 重复内容

android - native 应用程序比 HTML5 更快

ios - Swift 4.2 使用 UICollectionViewCell 添加/删除按钮

ios - Ionic pro - 构建并发布到 Apple Store

ios - 在 Swift 中制作 Gif 动画

protocols - 条件绑定(bind)中的绑定(bind)值必须是可选类型

ios - Swift firebase 文件上传

swift - Xcode 中的按钮是否有不止一层约束?

ios - UIView 没有隐藏,但它里面的按钮是?