自动版式视图使上popViewController应用程序崩溃 [英] AutoLayout views make app crash on popViewController

查看:198
本文介绍了自动版式视图使上popViewController应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最后更新 - 修正

我已经解决了这个问题。如此看来,虽然玩了(这是我在斯威夫特的第一个项目,并使用自动版式)我已经改变了 contentCom pressionResistancePriority contentHuggingPriority 对我的一些看法。采取这一code OUT和CH375复位我所有的意见为默认值IB固定我的问题。

I have fixed this. It seems that while playing around (this is my first project in Swift and using AutoLayout) I have changed the contentCompressionResistancePriority and contentHuggingPriority for some of my views. Taking that code out and reseting all my views to default values in IB fixed my problem.

战后初期

所以我使用iOS上的自动版式来定位我的动态视图。它的工作都好,易于
直到我弹出我的看法控制器之一。该应用程序崩溃与是这样的一个非常无益的错误消息:

So I am using AutoLayout on iOS to position my dynamic views. It's all working nice and easy until I pop one of my view controllers. The app crashes with a really not helpful error message that goes something like this:

...
internal error.  Cannot find an outgoing row head for incoming head UIImageView:0xd049d50.Width{id: 730}, which should never happen.'
...

我已经波金格周围,在网上搜索,但我不能修复它。我发现,虽然有我的code一条线,可以有所作为。在我说视图控制器我有一堆正在使用自动版式和谁的UIImageView 取值的图片我从网上加载。

I've been pocking around and searched the web but I cannot fix it. I've discovered though that there is one line in my code that can make a difference. In my said view controller I have a bunch of UIImageViews that are using AutoLayout and who's images I load from the web.

如果不是我接收到的图像设置为他们,我设置一个空的( [UIImage的ALLOC] INIT] 的UIImage()斯威夫特因为是我的情况完全一致)它不会崩溃了。

If instead of setting my received image to them I set an empty one ([[UIImage alloc] init] or UIImage()) in Swift as is my case exactly) it doesn't crash anymore.

我甚至尝试从应用程序包设置一个虚拟的形象,但是这使得它崩溃了。

I even tried setting a dummy image from the app bundle but that makes it crash too.

任何建议将是多少AP preciated!

Any suggestions would be much appreciated!

更新1

展望线槽code一次我还发现,有相关的约束的UIImageViews 这也使得碰撞时消除走开。这是一个纵横比约束,它看起来像这样

Looking trough the code once more I also found out that there is a constraint related to those UIImageViews that also makes the crash to go away when eliminated. It's an aspect ratio constraint and it looks like this

imageView.addConstraint(NSLayoutConstraint(item: imageView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: imageView, attribute: NSLayoutAttribute.Height, multiplier: 8.0 / 5.0, constant: 0.0))

我是不是做错了什么?我真的需要满足这方面的比例,所以我真的不能删除它。

Am I doing something wrong? I really need this aspect ratio to be satisfied so I can't really remove it

更新2

搞乱一点点吧,我想出一个办法让它工作。但我不喜欢它因为它没有使我明白是怎么回事,它是怎样的一个黑客

Messing a little bit more with it I've figured a way to make it work. But I'm not happy with it 'cause it didn't made me understand what's going on and it's kind of a hack

让我布置我的看法结构,您:

Let me layout my view structure to you:


  • 查看

    • 滚动查看

      • 内容查看

        • 封面ImageView的(从IB)

        • 标签标题(从IB)

        • ...从code的标签或ImageViews随机顺序...

        这些意见被放在的方法是这样的:

        The way these views are placed is like this:


        • 封面的ImageView 是一样宽的内容查看并具有8的纵横比:5,没有空间顶部

        • 每个标签有一个10px的前导空格和尾随10px的空间

        • 每个的ImageView 是一样宽的内容查看和具有8的纵横比:5

        • 所有观点都有10px的差距beewtwen他们,最后一个有10px的底部间隔的内容查看

        • The Cover ImageView is as wide as the ContentView and has an aspect ratio of 8:5 with no space on top
        • Each Label has a 10px leading space and a 10px trailing space
        • Each ImageView is as wide as the ContentView and has an aspect ratio of 8:5
        • All views have a 10px gap beewtwen them and the last one has 10px bottom spacing to the ContentView

        我定期到我的崩溃是从堆栈中删除内容查看 viewWillDisappear 但是,使屏幕闪烁时在ViewController中被弹出。

        My fix to my crash was to remove ContentView from the stack on viewWillDisappear but that makes the screen flash when the ViewController is popped.

        我检查了我的约束创建code 1000倍,这似乎是正确的。如果你想看到它让我知道,我会在这里发表过来

        I've checked my constraints creating code a 1000 times and it seems right. If you want to see it let me know and I'll post it over here

        推荐答案

        只是把这个位置的情况下,任何人有相同的问题动态,code产生的的aspectRatio 约束。我换了高的顺序宽度在宽高比约束(比作一个在问题)的关系:

        Just putting this here in case anyone has the same issue with a dynamic, code-generated aspectRatio constraint. I switched the order of the Height and Width relationship in the aspect-ratio constraint (compare to the one in the question):

        aspectConstraint = NSLayoutConstraint(item: cardMedia, attribute: NSLayoutAttribute.Height , relatedBy: NSLayoutRelation.Equal, toItem: cardMedia, attribute: NSLayoutAttribute.Width, multiplier: aspect, constant: 0.0)
        

        凡乘数纵横的计算方法是:

        let aspect = image.size.height / image.size.width
        

        这似乎阻止发生崩溃。希望这可以帮助别人。

        And that seems to stop the crash from happening. Hope this helps someone.

        这篇关于自动版式视图使上popViewController应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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