本文介绍了是什么导致这个错误? “CALayer位置包含NaN:[240纳米]”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我旋转一个有 UITableView 的屏幕时,我都会看到这种情况发生。我发现它发生在 UIViewController中 willRotate didRotate 方法调用之间/ code>我的同事也在其他地方看过它,通常在轮换周围。它直到最近才开始发生,我们对如何应对它感到困惑(谷歌搜索没有以确切的形式出现错误信息)。有没有其他人遇到过这个知道怎么做的事情?

I've seen this happen whenever i rotate a screen that has a UITableView on it. I've found out that it happens inbetween the willRotate and didRotate method calls in UIViewController My co-workers have seen it in other spots as well, usually around rotation. It hadnt started happening until very recently, and we're stumped as to how we should deal with it (google searches don't turn up the error message in its exact form). Has anyone else encountered this that knows what to do about it?

推荐答案

我发现了问题。

当你重置 tableview 的框架时,它会调用委托方法 tableView:heightForRowAtIndexPath:表中的每一行,以便在需要时重新计算其内容大小。那时,我们做了一些特殊的处理以返回高度,并且由于我们的代码中的一些错误的假设,我们错误地返回 NaN 由于零除错误(我们除以的变量假设从不为零)。确保我们不将零除以此处修复它。

When you reset the frame of a tableview, it calls the delegate method tableView:heightForRowAtIndexPath: for each row in the table so it can recalculate its content size if it needs to. At that point, we do some special handling to return the height, and due to some bad assumptions in our code, we mistakenly returned NaN due to a divide by zero error (the variable we divide by was assumed to never be zero). Making sure that we do not divide by zero here fixed it.

这篇关于是什么导致这个错误? “CALayer位置包含NaN:[240纳米]”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:47