当前位置:   iOS > 正文

UITableViewCell detailTextLabel没有显示出来

uitableview,ios,swift,xcode,DevBox,在线流程图,编程,编程问答,程序员,开发者工具,开发工具,json解析,二维码生成,unix时间戳,在线开发工具,前端开发工具,开发人员工具,站长工具

在Swift中使用a UITableView和它UITableViewCell的.我有一些问题显示了一个detailTextLabel领域UITableViewCell.

我已经发现这两个有用的职位,但无法得到充分有效的解决方案: 迅速detailTextLabel没有显示出来, 如何设置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为单元格使用正确的样式(),但我不知道如何将该更改集成到我的代码中.我见过的例子是基于子类化的UITableViewCell,我想我不需要继承子类UITableViewCell只是为了使用该detailTextLabel字段.请告诉我,如果我错了.

我也从上面提到的帖子中尝试了一些东西,但没有任何效果,因为我想要的.



1> Patrick..:

您已注册UITableViewCell

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

这意味着当你打电话时

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

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

因为你想要一个自定义样式,你需要做一些事情:

去掉

dequeueReusableCellWithIdentifier

更换

dequeueReusableCellWithIdentifier

以下内容

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

dequeueReusableCellWithIdentifier如果它不能使一个单元格出列,那么这里发生的将返回nil.然后,您可以使用指定的样式生成自己的单元格.

注意:写了没有Xcode,我是Swift的新手,如果它不编译就道歉.


我希望我给了你+10 ..!谢谢..!
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/iOS/detail/8018
推荐阅读
相关标签
  

闽ICP备14008679号