Swift 'text' 不可用:从 iOS7 开始不推荐使用 API.文本标签不起作用 [英] Swift 'text' is unavailable: APIs deprecated as of iOS7. textLabel does not work

查看:12
本文介绍了Swift 'text' 不可用:从 iOS7 开始不推荐使用 API.文本标签不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直有这个错误

我已经看到使用 textLabel.text 回答了其他问题,但在我的情况下不起作用

I've seen other questions been answered by using textLabel.text, but it doesn't work in my case

我是 swift 的新手,所以请有人解释我为什么以及如何解决这个问题.

I'm new to swift so could someone please explain me why and how to solve this.

推荐答案

您需要在 textLabel 之后使用 ! 来解开 textLabel.

You need to unwrap textLabel by using an ! after textLabel.

这是因为textLabel 是一个Optional(因此是textLabel? 类型,而不仅仅是textLabel).阅读更多关于选项 这里.

This is because textLabel is an Optional (hence the textLabel? type instead of just textLabel). Read more about optionals here.

希望有帮助!

这篇关于Swift 'text' 不可用:从 iOS7 开始不推荐使用 API.文本标签不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆