ios - 如何将 UILabel 转换为字符串?

标签 ios swift

我试图将 UILabel 转换为字符串,但总是失败。我还能怎么投呢? friendname 是一个 UILabel,friendusername 是一个字符串。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if (segue.identifier == "friendsSongs"){

        let nextViewOBJ = segue.destinationViewController as! FriendsMusic
        nextViewOBJ.friendusername = friendname as! String
    }
}

最佳答案

使用 text UILabel 上的属性:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if (segue.identifier == "friendsSongs"){

        let nextViewOBJ = segue.destinationViewController as! FriendsMusic
        nextViewOBJ.friendusername = friendname.text
    }
}

您不能将 UILabel 转换为字符串 - 但您可以找到 UILabel 的文本是什么。这就是您想在这里做的。

关于ios - 如何将 UILabel 转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33634766/

相关文章:

ios - URLSession dataTask completionHandler 在 Playground 上不起作用

ios - 当应用程序处于后台或终止状态时如何增加推送通知批处理计数

ios - UIAlertController 不显示多行消息

swift - 多个 UIPickerview 错误

swift - SKPhysicsContactDelegate,碰撞无法正常工作

ipad - iOS:在给定 Hz 参数的情况下,iPad 上的声音生成?

ios - 在 iOS 中动态添加一堆控件到屏幕

swift - URL session 问题

ios - 如何从 native iOS 应用程序重定向回使用深层链接/uni 链接启动我的应用程序的原始网页?

swift - 如何将数据从 AKSwiftSlideMenu 菜单传递到 Swift 中的 UIViewController?