HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UILabel在启动时不在自定义UITableViewCell中执行多行,但在滚动后执行大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
编辑#1

我在github添加一个项目链接
https://github.com/trestles/testtable

这是我第一次与Autolayout打交道,所以我希望我会做一些业余错误.老实说,我知道我是如何做这个操纵帧,但无法通过内容裁剪自动布局正常工作.部分问题是,如果我们总是处于纵向模式,@R_635_10675@用框架吗?

我有一个自定义的UITableViewCell,我有一些UILabel.它们设置为numberOfLines = 0.有时,他们会截断文本.像这样:

我该如何解决我试过在viewDidLoad中重新加载数据,但这似乎并不重要.大多数情况下,当您滚动时,它会自行修复(但并非总是如此).它可以是任何三个UILabel,并且与文本数量无关.我第一次使用带有自动布局的UILabels,所以很可能是我犯了一些错误.这是我的UILabel属性

和第一个标签的布局:

解决方法

您的自动布局非常完美,只是因为您在xib中使用认文本设置自动布局而出现问题.并在您viewDidLoad中,您正在更新UILabel文本但不以编程方式更新布局.所以只留下一行如下.
self.mainTV.layoutIfNeeded();

在viewDidLoad方法中重新加载UITableView之前添加上面的行.所有的事情都很好.

例:

override func viewDidLoad() {
    super.viewDidLoad()

    self.mainTV.datasource=self
    self.mainTV.delegate=self
    self.mainTV.rowHeight = UITableViewAutomaticDimension
    self.mainTV.estimatedRowHeight = 84.0
    //self.mainTV.registerClass(myTableViewCell.self,forCellReusEIDentifier: "MyCustomcatell")


    var tmps = [String]()

    tmps.append("ABC But here is an artist. He desires to paint you the dreamiest,shadiest,quietest,most enchanTing bit of romantic landscape in all the valley of the Saco. what is the chief element he employs?")
    tmps.append("DEF But here is an artist.")
    tmps.append("GHI But here is an artist. He desires to paint you the dreamiest,most enchanTing bit")

    for var i=0; i<10; i++
    {
      var menuItem=EKMenuItem()
      let randomIndex1 = Int(arc4random_uniform(UInt32(tmps.count)))
      menuItem.header = "\(i) \(tmps[randomIndex1])"

      let randomIndex2 = Int(arc4random_uniform(UInt32(tmps.count)))
      menuItem.detail = "\(i) \(tmps[randomIndex2])"
      let randomIndex3 = Int(arc4random_uniform(UInt32(tmps.count)))
      menuItem.price = "\(i) \(tmps[randomIndex3])"
      //tmpItem.price = "my price"
      dataItems.append(menuItem)
    }

    self.view.BACkgroundColor = UIColor.greenColor()

    self.mainTV.layoutIfNeeded();
    self.mainTV.reloadData()
    // Do any additional setup after loading the view,typically from a nib.
  }

希望这对你有所帮助.

大佬总结

以上是大佬教程为你收集整理的ios – UILabel在启动时不在自定义UITableViewCell中执行多行,但在滚动后执行全部内容,希望文章能够帮你解决ios – UILabel在启动时不在自定义UITableViewCell中执行多行,但在滚动后执行所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。