根视图消失

时间:2014-08-22 16:42:26

标签: objective-c ios7 uiviewcontroller uinavigationcontroller modalviewcontroller

我有以下代码来测试一些模态演示。我尝试通过UINavigationController呈现UBSLoginViewController,然后在UBSLoadingViewController上以透明背景模式呈现UBSLoginViewController,等待一段时间,然后将其解除。

会发生什么:

  1. 显示登录视图,

  2. 加载视图在登录视图上显示透明,

  3. 登录视图消失或加载视图中的透明度消失。无论哪种方式,登录视图在加载视图后面都不再可见。

  4. 不解除加载视图。

  5. 我在下面收到两条警告。一个是登录视图的第一个演示文稿,第二个是关闭尝试(底部警告1):

    2014-08-22 11:37:52.525 Uberscore[72349:60b] Warning: Attempt to dismiss from view controller <UINavigationController: 0x8c4cfc0> while a presentation or dismiss is in progress!
    2014-08-22 11:37:53.088 Uberscore[72349:60b] Unbalanced calls to begin/end appearance transitions for <UINavigationController: 0x8c4cfc0>.
    

    以下代码:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        //Prep window
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
        //Set up and display login controller
        UBSLoginViewController* loginView = [[UBSLoginViewController alloc] initWithNibName:LOGINVIEW bundle:nil];
        UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:loginView];
        navigation.navigationBarHidden = YES;
        self.window.rootViewController = navigation;
        [self.window makeKeyAndVisible];
        [loginView presentViewController:[[UBSLoadingViewController alloc] initWithNibName:LOADINGVIEW bundle:nil] animated:YES completion:nil];
        int timeout = 3000;
        wait(&timeout);
        [loginView dismissViewControllerAnimated:YES completion:nil];
        return YES;
    }
    

1 个答案:

答案 0 :(得分:0)

你用这一行解雇了loginView

[loginView dismissViewControllerAnimated:YES completion:nil];

您想要在加载视图上调用dismissViewControllerAnimated:completion:

UBSLoadingViewController *loadingView = [[UBSLoadingViewController alloc] initWithNibName:LOADINGVIEW bundle:nil];
[loginView presentViewController:loadingView animated:YES completion:nil];
...
// Later on to dismiss the loading view
[loadingView dismissViewControllerAnimated:YES completion:nil];