ios7 navigationController pushViewController动画bug [英] ios7 navigationController pushViewController animated bug

查看:103
本文介绍了ios7 navigationController pushViewController动画bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来我在navigationController pushViewController方法中发现了一个错误。为了重新创建它,我采用了示例主详细信息项目并对 -didSelectRow:方法进行了一些更改:

It looks like I found a bug in the navigationController pushViewController method. To recreate it I took the sample master detail project and made some changes to the -didSelectRow: method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailViewController* view = [self.storyboard instantiateViewControllerWithIdentifier: @"view"];
    NSDate *object = _objects[indexPath.row];
    [view setDetailItem:object];
    [self.detailViewController.navigationController pushViewController:view animated:YES];
}

我还将详细信息视图的故事板ID更改为查看。这是发生的事情:

I also changed the storyboard ID of the detail view to "view". Here's what happens:

当慢慢选择任何主人的行时(当推动动画完成时)它工作正常:

When selecting any of master's rows slowly (when the push animation has finished) it works fine:

如果在动画仍在显示时选择任何行,详细视图变为非活动状态(显示在bug之前使用push方法调用的最后一行),只有导航栏显示新视图的推送动画:

If you select any of the rows while the animation is still showing, the detail view becomes inactive (shows the last row that was called with the push method before the bug) and only the navigation bar shows the push animation of a new view:

当发生这种情况时,您会在调试器输出中收到一些警告:

When this happens you get some warnings in the debugger output:

Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.

nested push animation can result in corrupted navigation bar

Unbalanced calls to begin/end appearance transitions for <DetailViewController: 0x8a6e070>.

这是令人讨厌的部分:如果你回到详细视图的导航栏然后选择另一行在Master的tableview中或在详细信息中返回两次应用程序崩溃

Here's the nasty part: if you go back on the detail view's navigation bar and then select a different row in Master's tableview OR go back twice in the Detail the app crashes with

Can't add self as subview

但如果您在ios6上运行相同的代码,它可以正常运行。

BUT if you run the same code on ios6 it works without any problems or warnings.

当前解决方案:

使用动画调用方法:NO似乎没有任何问题,显然没有推送动画。

Calling the method with animated:NO seems to work without any problems, obviously there's no push animation.

另一个解决方案是在Master中设置一个布尔值,在调用push方法时将其设置为false,并从Detail in Detail的viewDidAppear中将其设置为true。这样,您可以在调用push方法时检查该值。缺点:如果您尝试快速选择同一行,tableView可能会显得滞后,如果您快速选择另一行然后它将不会显示在详细信息中但它将在主表视图中被选中并突出显示,您可以保存所选行的索引并更改代码中的选择,但这会导致闪烁的行突出显示。

Another solution is to have a boolean value in Master set it to false when calling the push method and setting it to true from Detail in Detail's viewDidAppear. That way you can check the value when calling the push method. Drawbacks: the tableView might appear laggy if you try to quickly select the same row, if you select a different row quickly then it wont show up in Detail but it will get selected in the Master tableview and get highlighted, you can save the selected row's index and change the selection in code but that leads to flickering row highlighting.

两种解决方案都涉及一些妥协,所以我想找到另一种处理方法。有没有更好的解决方案?

Both solutions involve some compromise, so I'd like to find another way of handling this. Are there any better solutions?

推荐答案

经过一些测试后,在ios6中,当一个tableview单元格被选中并且推送被调用时tableview将 .allowsSelection 设置为 NO ,直到推送结束。

After some testing it appears that in ios6 when a tableview cell gets selected and the push gets called the tableview sets .allowsSelection to NO until the push ends.

通过将 .allowsSelection 设置为 NO didSelectRowAtIndexPath:中的push方法之后,并在详细信息视图的 didAppear:方法中进行回调我们在主视图中将tableview的 .allowsSelection 设置为 YES

This can be easily reproduced in ios7 by setting .allowsSelection to NO after the push method in didSelectRowAtIndexPath: and having a callback in the didAppear: method of the detail's view where we set the tableview's .allowsSelection to YES in the master view.

虽然这种方法非常好,但我发现在一个接一个地快速选择两个不同的单元格时会觉得有点烦人,第二个单元格会被忽略。

While this works perfectly fine I found it a bit annoying when quickly selecting two different cells one after the other that the second one will get ignored.

所以我已设置如果在推动动画尚未结束时选择了另一个单元格,则保存对新视图的引用,并在第一个动画结束后立即推送它。通过这样做,我认为tableView似乎更具响应性。

So i've set up that if another cell is being selected while the push animation hasn't ended I save a reference to the new view and push it as soon as the first animation has ended. By doing this the tableView seems a bit more responsive in my opinion.

这篇关于ios7 navigationController pushViewController动画bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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