使用大小类时,UITableViewCell子视图报告的宽度不正确 [英] UITableViewCell subviews report incorrect width when using size classes

查看:131
本文介绍了使用大小类时,UITableViewCell子视图报告的宽度不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,在xcode 6中使用大小类时,我的单元格中的子视图的宽度不正确。我有一个 UIImageView ,其中包含自动布局大小(常量:顶部为10,L / R,底部)。

For some reason, when using size classes in xcode 6, I am getting incorrect widths for subviews in my cell. I have a UIImageView with autolayout for sizing (constant: 10 for top, L/R, bottom).

tableView(tableView:UITableView!,cellForRowAtIndexPath indexPath:NSIndexPath!)调用以下内容时

println("w: \(cell.mapSnapshotImageView.bounds.size.width) h: \(cell.mapSnapshotImageView.bounds.size.height)")

我总是得到:

w: 580.0 h: 80.0

即使 w:300.0 h:80.0 基于我在iPhone 5S上的320x100单元格。

Even though it should be w: 300.0 h: 80.0 based on my 320x100 cell on an iPhone 5S.

一切都显示正确,但我想使用宽度其他子视图的一些计算的子视图。有关为什么会发生这种情况的任何想法?错误报告或按设计工作?

Everything displays correctly, but I want to use the width of the subview for some calculations for other subviews. Any ideas as to why this is happening? Bug report or working as designed?

编辑:

此问题仅适用于此到最初加载的单元格。当细胞被重复使用时,问题不会出现。 println 重复使用的单元格输出:

This issue only applies to cells that are loaded initially. When cells are reused, the issue does not present itself. println output on reused cells:

w: 300.0 h: 80.0


推荐答案

我也遇到过这个问题。当您动态更改视图的大小时,子视图需要相应地更新其值。您在更新之前引用这些值。

I also ran into this issue. When you dynamically change the size of the views the subviews need to update their values accordingly. You are referencing the values before they have been updated.

我的工作是在更新后引用这些值。在这种情况下,它位于viewDidAppear()中。希望这提供了一些用途。我花了一些时间试图搞清楚。

My work around was to reference the values after they had been updated. In this case it was in viewDidAppear(). Hope this provides some use. I spent a while trying to figure it out.

这篇关于使用大小类时,UITableViewCell子视图报告的宽度不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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