UITableViewCell detailTextLabel没有显示

米歇尔

在Swift中使用aUITableView及其UITableViewCell(s)。我在显示的detailTextLabel字段时遇到一些问题UITableViewCell

我已经找到了这两个有用的帖子,但是找不到完整的解决方案:swift detailTextLabel不显示 如何在Swift中设置UITableViewCellStyleSubtitle和dequeueReusableCell?

这是我使用的与我的问题有关的代码:

override func viewDidLoad() {
    super.viewDidLoad()

………….
    theTableView = UITableView(frame: tmpFrame)
………….
    theTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "reuseIdentifier")
    theTableView.dataSource = self
    theTableView.delegate = self
    self.view.addSubview(theTableView)
}


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", forIndexPath: indexPath)
    cell.backgroundColor = UIColor.clearColor()
    cell.textLabel?.text = "THE-TEXT-LABEL"
    cell.detailTextLabel?.text = "KIJILO" // This does not show up.
    return cell
}

当我尝试使用的detailTextLabel字段时UITableViewCell,它没有显示。在网上搜索时,我了解到必须UITableViewCellStyle为单元格使用适当的style(),但是我看不到如何将更改集成到代码中。我看到的示例都是基于子类的UITableViewCell,我想我不需要UITableViewCell子类即可使用该detailTextLabel字段。如果我错了,请告诉我。

我也从上面提到的帖子中尝试了一些方法,但是没有任何所需的方法。

帕特里克

您已经注册了UITableViewCell

theTableView.registerClass(UITableViewCell.self,
 forCellReuseIdentifier: "reuseIdentifier")

这意味着当您致电

tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", 
forIndexPath: indexPath)

将使用UITableViewCellStyleDefault样式自动为您创建一个样式。

因为您想要自定义样式,所以需要做一些事情:

消除

theTableView.registerClass(UITableViewCell.self, 
forCellReuseIdentifier: "reuseIdentifier")

代替

var cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier", 
forIndexPath: indexPath)

与以下

var cell = tableView.dequeueReusableCellWithIdentifier("reuseIdentifier")
if cell == nil {
    cell = UITableViewCell(style: .Value1, reuseIdentifier: "reuseIdentifier")
}

dequeueReusableCellWithIdentifier如果无法使单元出队,则这里发生的情况将返回nil。然后,您可以生成具有指定样式的自己的单元格。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

UITableViewCell.detailTextLabel在加载时不显示

来自分类Dev

UITableViewCell不显示detailTextLabel.text-Swift

来自分类Dev

如何在UITableViewCell中显示detailTextLabel?

来自分类Dev

UITableViewCell.detailTextLabel在加载时不显示

来自分类Dev

UITableViewCell textLabel没有显示为可选

来自分类Dev

我的 uitableviewCell 的内容没有显示?

来自分类Dev

滚动时UITableViewCell detailTextLabel消失

来自分类Dev

iOS:AutoLayout UITableView-> UITableViewCell没有显示正确的大小

来自分类Dev

UITableViewCell 没有正确着色

来自分类Dev

UITableViewCell detailTextLabel即使使用不同的单元格样式也不会显示

来自分类Dev

Why is a UITableViewCell detailTextLabel optional in Swift whereas the textLabel is not

来自分类Dev

在计算UITableViewCell高度时,自动布局会忽略多行detailTextLabel(所有样式)

来自分类Dev

如何在UITableViewCell中具有两个单独的detailTextLabel值?

来自分类Dev

如何从uitableviewcell显示uidatepicker

来自分类Dev

UITableViewCell字幕未显示

来自分类Dev

UITableViewCell内容不显示

来自分类Dev

UITableViewCell不显示

来自分类Dev

UITableViewCell不显示内容

来自分类Dev

UITableViewCell显示错误的内容

来自分类Dev

UITableViewCell内容不显示

来自分类Dev

UITableViewCell不显示

来自分类Dev

带有xib的UITableViewCell

来自分类Dev

带有xib的UITableViewCell

来自分类Dev

“ UITableViewCell?” 没有名为“ textLabel”的成员

来自分类Dev

“UITableViewCell”类型的值没有成员

来自分类Dev

没有 TableView 的 StackView 中的 UITableViewCell

来自分类Dev

如何禁用UITableViewCell高亮显示?

来自分类Dev

UITableViewCell的辅助箭头未显示

来自分类Dev

UIImageView显示在错误的UITableViewCell中

Related 相关文章

热门标签

归档