本文介绍了UINavigationController:在iPad上正在解除另一个控制器时呈现视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要用户登录的视图。当用户尝试打开该视图时他没有登录我将调用登录视图供他登录,完成后我将调用原始视图他打算看看。

在iPhone上,当我在那里推动视图控制器时这很好用。
但是在我提供视图控制器的iPad上,这不起作用。它说解雇正在进行中,无法显示新的控制器。以下是代码:

I have a view that requires user to be logged in. When the user attempts to open that view an he is not logged in I will call the login view for him to login and after he is done I will call the original view that he intended to see.
On iPhone this works fine as I push view controllers there.But on iPad where I present view controller this does not work. It says that dismissal in progress, can't show new controller. Here is the code:

- (void) buttonPressed
{
    if (!userLoggedIn) { // userLoggedIn getter calls new screens of login if needed
    return;  // this is executed if user declined to login
    }
    MyViewController *temp = [[MyViewController alloc] init];
    [self.navigationController presentViewController:temp animated:YES]; // this returns warning that dismissal in progress and does not work
}

我能做什么?这样做?在iPhone上我的所有逻辑工作正常,但在iPad上它失败了。我在很多地方使用它并且完全重写代码并不好。

What can I do about that? On iPhone all of my logic works fine, but on iPad it fails. I use it in many places and completely rewriting code is not good.

编辑:更多代码:

- (BOOL) userLoggedIn {
   // code omitted
    [centerController presentViewController:navController animated:YES completion:nil];
   // code omitted
   [centerController dismissViewController:navController animated:YES]; // setting to NO does not fix my problem
   return YES;
}

EDIT2:
这是iPad的代码。我删除了与iPhone相关的代码。它在iPhone上的作用 - 而不是呈现控制器,它使用推动,在这种情况下一切正常。

This is the code for iPad. I have removed iPhone-related code. What it does on iPhone - instead of presenting controller it uses pushing, and in that situation everything works fine.

推荐答案

你不能在场只要解除你的第一个观点没有完成,另一个观点。解雇视图的动画应在呈现新视图之前完成。因此,您可以在解雇时将其动画设置为,或使用
performSelector:withObject:afterDelay:
并在2-3秒后显示下一个视图。

You cannot present another view as long as the dismissing of your 1st view is not complete. The animation of dismissing view should be completed before presenting new view. So, either you can set its animation to NO while dismissing, or use performSelector:withObject:afterDelay:and present the next view after 2-3 seconds.

希望这有帮助。

这篇关于UINavigationController:在iPad上正在解除另一个控制器时呈现视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 08:55