为什么我的UITableView的格式完全走歪,当我从我segued到一个视图控制器返回? [英] Why does my UITableView's formatting go completely awry when I return from a view controller I segued to?

查看:96
本文介绍了为什么我的UITableView的格式完全走歪,当我从我segued到一个视图控制器返回?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的UITableView 使用自定义的电池,它有它的几个标签动态决定细胞的高度。当我点击在一个单元格,Segue公司到一个新的视图控制器,在返回所有格式的单元格是完全搞砸了,我也弄不清是什么原因造成的。

I have a UITableView with a custom cell, which has a few labels in it that dynamically decide the height of the cell. When I tap on one cell and segue to a new view controller, upon returning all the formatting for the cells is completely messed up, and I can't figure out what is causing it.

下面是细胞通常是这样的:

Here is what the cells normally look like:

和我对他们设置一些pretty基本约束。顶部标签被固定在顶部和左侧的利润,而且必须始终从右边> = 20。其他标签对准该第一标签的左侧,与垂直间距个个之间。中间标签具有权利间距约束到边界,和底标签被对准至第一基线和具有所有这些之间的水平间距。

And I have some pretty basic constraints set on them. The top label is pinned to the top and left margins, and must always be >= 20 from the right. The other labels are aligned to the left of this first label, with vertical spacing set between all of them. The middle label has a right spacing constraint to the margin, and the bottom labels are aligned to the baseline of the first and have horizontal spacing between all of them.

当我Segue公司回到这个表中查看它看起来像这样但是:

When I segue back to this table view it looks like this however:

我也弄不清是什么原因造成它比布局我离开的时候不同。如果我周围滚动似乎复位他们回到他们应该是什么,但在初始加载他们真的搞砸了。如果需要,我可以附加项目,但实在是没有太多故事板之外。

I can't figure out what is causing it to layout differently than when I left. If I scroll around it seems to "reset" them back to what they should be, but on initial load they're really messed up. I can attach the project if desired, but there's really not much outside of the Storyboard.

的cellForRowAtIndexPath:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as CustomTableViewCell

    let object = objects[indexPath.row]

    cell.title1.text = object.name
    cell.title2.text = object.color
    cell.title3.text = object.roar

    return cell
}

示例项目: http://cl.ly/040L2z0q0V2d

推荐答案

看来,从SEGUE返回时表视图细胞不调整大小的基础上的内容。使用示例项目,我在viewWillAppear中扔了重载数据和似乎解决这​​个问题。

It appears that the table view cells aren't resizing based on the contents when returning from the segue. Using the sample project, I threw a reload data in the viewWillAppear and that seemed to fix the issue.

override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    self.tableView.reloadData()
}

这篇关于为什么我的UITableView的格式完全走歪,当我从我segued到一个视图控制器返回?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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