xcode UINavigationController'损坏的导航栏'问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19518856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:09:08  来源:igfitidea点击:

UINavigationController 'corrupted navigation bar' issue

iosobjective-cxcodecocoa-touchinterface-builder

提问by Michael

I'm having serious problems getting my navigation controller to work and have tried pretty much every related question on this website.

我在让我的导航控制器工作时遇到了严重的问题,并且在这个网站上尝试了几乎所有相关的问题。

My problem is that when I perform a segue programmatically, there appears to be a transition in the navigation bar, but the view doesn't change. I see the following errors instead:

我的问题是,当我以编程方式执行 segue 时,导航栏中似乎有一个过渡,但视图没有改变。我看到以下错误:

2013-10-22 13:47:30.059 App[2236:a0b] nested push animation can result in corrupted navigation bar
2013-10-22 13:47:30.411 App[2236:a0b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2013-10-22 13:47:30.501 App[2236:a0b] Unbalanced calls to begin/end appearance transitions for 

My storyboard looks like this:

我的故事板看起来像这样:

enter image description here

在此处输入图片说明

In LoginViewController we perform a segue based on some condition:

在 LoginViewController 中,我们根据某些条件执行 segue:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear];
    NSString* appState = [AppConfig getAppState];
    if ([appState isEqualToString:APP_STATE_WAITING]) {
        [self performSegueWithIdentifier:@"Load" sender:self];
    }
    else if ([appState isEqualToString:APP_STATE_REGISTRATION_AVAILABLE]) {
        [self performSegueWithIdentifier:@"SignUp" sender:self];
    }
}

In LoadingViewController we wait for a response from a web service before doing:

在 LoadingViewController 中,我们在执行以下操作之前等待来自 Web 服务的响应:

- (void)segueToWaitingList:(NSUInteger)behind inFront:(NSUInteger)inFront
{
    [MosaycOptions setAppState:APP_STATE_WAITING];
    dispatch_async(dispatch_get_main_queue(), ^{
         [self performSegueWithIdentifier:@"Waiting" sender:self];
    });
}

And it is that segue that gives me the problem. The nav bar transitions but the view does not and we see the following errors printed out:

正是那个 segue 给了我这个问题。导航栏转换但视图没有转换,我们看到打印出以下错误:

2013-10-22 13:47:30.059 App[2236:a0b] nested push animation can result in corrupted navigation bar
2013-10-22 13:47:30.411 App[2236:a0b] Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
2013-10-22 13:47:30.501 App[2236:a0b] Unbalanced calls to begin/end appearance transitions for 

The app doesn't crash, but no segue occurs, it doesn't transition to the waiting list view but simply stays on Loading and prints the error to console. When I press back rather than moving back to the login screen I get the following blank screen:

应用程序不会崩溃,但不会发生 segue,它不会转换到等待列表视图,而只是停留在加载中并将错误打印到控制台。当我按下返回而不是返回登录屏幕时,我得到以下空白屏幕:

enter image description here

在此处输入图片说明

If I press back again it crashes with this error: http://pastebin.com/7mCyeQv9

如果我再次按下它会崩溃并出现此错误:http: //pastebin.com/7mCyeQv9

Something is clearly getting messed up with the navigation stack, however i've inspected it using the debugger and it looks absolutely fine, everything gets pushed as normal. I can't for the life of me figure it out. This is just a standard navigation controller setup that i've used before.

导航堆栈显然有些混乱,但是我已经使用调试器检查过它,它看起来非常好,一切都像往常一样被推送。我一辈子都搞不清楚。这只是我以前使用过的标准导航控制器设置。

Any ideas?

有任何想法吗?

回答by Michael

I finally figured out the problem.

我终于想通了问题所在。

performSegueWithIdentifierwas being called before viewDidAppearwas called on the LoadingViewController. A synchronisation error basically.

performSegueWithIdentifierviewDidAppear在 LoadingViewController 上调用之前被调用。基本上是同步错误。

回答by adnako

You should not perform segue in viewDidLoad. Try performing in viewDidApperar:

您不应该在viewDidLoad 中执行 segue 。尝试在viewDidApperar 中执行

Apple documentation:

苹果文档

Displaying a View Controller's Contents Programmatically … Present it from another visible view controller. …

以编程方式显示视图控制器的内容……从另一个可见的视图控制器呈现它。…