iOS:在标签成功之前无法显示登录

Posted

技术标签:

【中文标题】iOS:在标签成功之前无法显示登录【英文标题】:iOS : Fail to show Login prior to Tabs Successfully 【发布时间】:2014-04-01 06:47:58 【问题描述】:

我知道这个问题在 *** 上出现过很多次,在互联网上也出现过很多次。我也问过相同的问题,但上下文不同,所以请多多包涵,因为我无法找到此任务的解决方案。

我正在使用 Xcode 5,使用 Storyboard。我的项目是基于选项卡的,并在情节提要中添加了一个 LoginViewController。我的胜利是在选项卡之前显示 LoginViewController。我从各个站点尝试了几种方法,但没有一个完全有效。使用此代码,我首先可以获得 LoginViewController,但无法获得 Tabs 控制器。在我的 AppDelegate 中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

// Override point for customization after application launch.    
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
self.tabBarController = [[MC_MainTabBarController alloc] init];

LoginViewController *loginViewController = [storyboard instantiateViewControllerWithIdentifier:@"loginViewController"];
[self.window setRootViewController:loginViewController];

// This also works - it shows the login
//[[[[UIApplication sharedApplication] delegate] window] setRootViewController:loginViewController];

// With this Login doesn't come only
//[loginViewController setModalPresentationStyle:UIModalPresentationFullScreen];
//[tabCtrler presentViewController:loginViewController animated:NO completion:nil];

return YES;

在我的 LoginViewController.m 中 - 在 loginBtnClicked 事件结束时,我调用:

    NSLog(@"Showing TabController");
MC_AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[appDelegate.window setRootViewController:appDelegate.tabBarController];

在执行上述行时,我得到黑屏和以下警告:

Showing TabController
Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation.
Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation.

谁能帮帮我。我从过去 2 天开始就被这个问题困住了。

非常感谢任何帮助。

【问题讨论】:

也许我的回答可以帮到你:***.com/questions/19962276/… @dimimpou,非常感谢。你的回答帮助了我。也得到了通知的想法。尽管我为我的问题实施了 Trevor Gehman 的回答,但也从您的回答中采纳了想法。谢谢。 【参考方案1】:

你确定 MC_MainTabBarController 是 UITabBarController 的子类吗? (我猜是) 因为当TabBar不是rootViewController时会出现这个错误

而不是 [[MC_MainTabBarController alloc] init];我会从情节提要 [storyboard instantiateViewControllerWithIdentifier:@"myTabBarIdentifier"] 分配标签栏控制器;

我尝试过,它对我有用:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    _tabController = [storyboard instantiateViewControllerWithIdentifier:@"tabbcontrolllerid"];
     LoginViewController *login = [[LoginViewController alloc]initWithNibName:@"LoginViewController" bundle:nil];
    [_window setRootViewController:login];
    return YES;

和你一样的登录按钮

- (IBAction)goToApp:(id)sender 
    stackAppDelegate *app = [UIApplication sharedApplication].delegate;
    [app.window setRootViewController:app.tabController];

标签栏是一个自定义的 TabBarController,它是 UITabBarController 的子类 我已经在情节提要中设置了我的自定义标签栏的标识符。

【讨论】:

感谢您的快速解决方案。是的,初始化我的 tabController 是问题所在。我实现了那个方法,它确实有效。尽管我实现了 Trevor Gehman 在 dimimpou 链接中显示的答案,但概念正如您所提到的 - 将 storyboardId 提供给 TabController 并通过情节提要初始化。再次感谢。

以上是关于iOS:在标签成功之前无法显示登录的主要内容,如果未能解决你的问题,请参考以下文章

无法在标签栏 iOS Swift 中显示图标

为啥我的自定义表格单元格中的标签在单击行之前无法显示

登录屏幕后显示侧边菜单

iOS facebook 登录问题

管理员链接显示 404 WordPress

在 UITabBarController 之前呈现登录视图控制器