为什么 UITableViewCell detailTextLabel 在 Swift 中是可选的,而 textLabel 不是 [英] Why is a UITableViewCell detailTextLabel optional in Swift whereas the textLabel is not

查看:31
本文介绍了为什么 UITableViewCell detailTextLabel 在 Swift 中是可选的,而 textLabel 不是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我以某种方式区分了?"和 "!"用快速的语言.但是在工作时,我遇到了一些让我更加困惑的事情.

I think I somehow got the different between "?" and "!" in swift language. But while working I faced something that made me more confused.

在使用 tableview 时,我在 UITableViewCell

While working with tableview I found the following datatypes in UITableViewCell

textLabeldetailTextLabel?

我的问题是:即使 textLabel 也可能为零,为什么 detailTextLabel? 是可选的??

My question is: why is detailTextLabel? optional even if textLabel may be nil too??

推荐答案

detailTextLabel 是可选的,因为它可能为零.检查 文档:

The detailTextLabel is optional because it can potentially be nil. Check the documentation:

如果样式不支持细节标签,则返回 nil.看UITableViewCellStyle 用于描述当前的主标签定义的单元格样式.

If the style doesn’t support detail labels, nil is returned. See UITableViewCellStyle for descriptions of the main label in currently defined cell styles.

因此,如果您的表视图样式不支持详细信息标签,则访问 detailTextLabel 将返回 nil.因此它是可选的.

So if your table view style doesn't support detail labels accessing the detailTextLabel will return nil. Hence its optional.

另一方面,textLabel 是根据需要创建的,因此它不是可选的:)

The textLabel on the other hand is created if needed hence it is not an optional:)

这篇关于为什么 UITableViewCell detailTextLabel 在 Swift 中是可选的,而 textLabel 不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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