簡體   English   中英

呈現登錄UINavigationController顯示黑屏

[英]Presenting login UINavigationController shows black screen

我的iOS應用程序需要用戶身份驗證,並且當用戶未通過身份驗證時,該應用程序應顯示一個ViewController,用戶可以在其中登錄。 該屏幕還為用戶提供了創建帳戶的選項,因此,可以使用以編程方式顯示的UINavigationController設置整個登錄屏幕(和可選的注冊屏幕)。

登錄屏幕顯示以下代碼:

- (void)promptCredentials{
    dispatch_async(dispatch_get_main_queue(), ^{
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *loginScreenNav = [storyboard instantiateViewControllerWithIdentifier:@"LoginNavigationController"];
        [loginScreenNav setModalPresentationStyle:UIModalPresentationFullScreen];
        [self presentModalViewController:loginScreenNav animated:YES];
    });
}

但是,調用此方法時,應用程序導航到黑屏 在此處輸入圖片說明 以編程方式向用戶展示其他ViewController的正確方法是什么? 我發現了幾個與此類黑屏有關的SO問題,但是,沒有一個答案對我有用。 我的應用程序在iOS 8.2上運行。

您需要創建一個UIViewcontroller並將其設置為您的UINAvigationController的rootController。

從ios6開始不推薦使用presentModalViewController,請嘗試使用presentViewController。

UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginNavigationController"];

UINavigationController  *loginScreenNav = [[UINavigationController alloc] initWithRootViewController:vc];

[self presentViewController:loginScreenNav animated:YES];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM