“对DetailViewController的开始/结束外观转换的不平衡调用”当推送多个细节视图控制器时 [英] "Unbalanced calls to begin/end appearance transitions for DetailViewController" when pushing more than one detail view controller

查看:101
本文介绍了“对DetailViewController的开始/结束外观转换的不平衡调用”当推送多个细节视图控制器时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含表格视图的视图控制器,可以选择表格中的项目和正确创建的详细视图控制器。

I have a view controller that contains a table view, the items in the table can be selected and a detail view controller duly created.

表格中的项目表示可以具有与其关联的基于时间的触发器的项目,并为每个项目安排本地通知,如果应用程序在本地通知到期时位于前台,则会自动显示该项目的详细信息视图。

The items in the table represent items that can have a time based trigger associated with them and a local notification is scheduled for each item, if the app is in the foreground when a local notification expires then the detail view for the item is automatically displayed.

我遇到一个问题,当两个通知同时到期导致视图无法正常显示以及控制台日志时出现:
不平衡的调用开始/ NNN的结束外观转换其中NNN是我的详细视图控制器。

I have a problem that manifests when two notifications expire at the same time which results in the views not being displayed properly and in addition the console logs: "Unbalanced calls to begin/end appearance transitions for NNN" where NNN is my detail view controller.

表视图控制器创建如下:

The table view controller is created as follows:

 self.tableViewController = [[TableViewController alloc] initWithNibName:@"TableView" bundle:nil];
 UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.tableViewController];
 self.window.rootViewController = navController;

当本地通知到期且didReceiveLocalNotification:被调用时,app会使用NSNotifcationCenter postNotificationName:来广播通知表视图控制器正在侦听。当表视图控制器收到该通知时,它会创建详细视图控制器并将其推送到堆栈:

When a local notification expires and didReceiveLocalNotification: is invoked the app broadcasts a notification using NSNotifcationCenter postNotificationName: and to which the table view controller is listening for. When the table view controller receives that notification it creates the detail view controller and pushes it to the stack as:

[self.navigationController pushViewController:detailViewController animated:YES]; 

我在某处读到如果视图控制器推送另一个视图控制器时可能会出现问题不在堆栈的顶部 - 所以我认为这一定是问题所在,因为当表视图控制器收到第二个通知时它将不再位于导航堆栈的顶部,因为它之前只是推送了一个详细视图控制器第一个通知到达时堆栈。

I read somewhere that there could be a problem if a view controller pushes another view controller when it itself is not on the top of the stack - so I thought this must be the problem, because when the table view controller receives the 2nd notification it will no longer be on the top of the navigation stack because it will have previously just pushed a detail view controller onto the stack when the first notification arrived.

所以我将推送代码更改为:

So I changed the push code to this:

[[self.navigationController topViewController].navigationController pushViewController:detailController animated:YES];

但没有区别。

所以我接下来认为可能会出现问题,因为第一个细节视图控制器没有机会在第二个
视图控制器被推送之前完全显示 - 所以我改变了我的应用程序的通知发布使用:

So I next thought there could be a problem because the first detail view controller was not getting the chance to fully display before the 2nd view controller was pushed - so I changed my app's notification posting from using:

[[NSNotificationCenter defaultCenter] postNotificationName: 

[[NSNotificationQueue defaultQueue] enqueueNotification: postingStyle:NSPostWhenIdle]

因此推送不会在app循环的同一次迭代中发生。但这没有任何区别,也没有尝试引入延迟推送详细视图控件:

So that the pushes wouldn't occur within the same iteraction of the app loop. But that made no difference, nor did attempting to introduce a delay to the pushing of the detail view controlle:

double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [[self.navigationController topViewController].navigationController     pushViewController:detailController animated:YES]; 
});

我不知道问题是什么或接下来要尝试什么,任何想法?

I've no idea what the problem is or what to try next, any ideas?

推荐答案


开始/结束外观转换的不平衡调用

"The unbalanced calls to begin/end appearance transitions"

在当前视图控制器完成显示之前尝试显示新的viewcontroller时发生。你可以通过在viewWillAppear中导航来重现它。

occurs when you try and display a new viewcontroller before the current view controller is finished displaying. You can reproduce it by navigating in viewWillAppear.

基本上你几乎在同一时间尝试将两个视图控制器推入堆栈。建议您在tableview控制器中维护一个队列,该队列维护一个需要显示的详细视图列表。一次按一个到堆栈并检查退出当前详细信息视图是否有任何需要显示的排队详细信息视图。

Basically you are trying to push two view controllers onto the stack at almost the same time. Suggest you maintain a queue in the tableview controller which maintains a list of the detail views which need displaying. Push one at a time on to the stack and check on exit from the current detail view whether there are any queued detail views which need displaying.

这种导航正在进行使用户感到困惑。最好考虑让您的详细信息视图支持多个项目。

This kind of navigation is going to be confusing for the user. It may be better to consider making your detail view support multiple items.

这篇关于“对DetailViewController的开始/结束外观转换的不平衡调用”当推送多个细节视图控制器时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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