我的项目首先使用 UITabBarController 作为第一个出现的 View 创建,然后我需要添加一个显示 3 秒的自定义启动画面,所以我使用了一个出现在 UITabBarController 之前的新 UIViewController 并且我设置了这个自定义启动画面作为第一个出现的 View 。但是,在我做了那个改变之后。目前我的初始屏幕转到 UITabBarController,我收到了这个错误。
警告:尝试在 SplashViewController 上呈现 UITabBarController:0x1cdcfe30:0x1cdc55e0 其 View 不在窗口层次结构中!
我以这种方式在我的 SplashViewController 中执行 View 更改:
#import "SplashViewController.h"
@interface SplashViewController ()
@end
@implementation SplashViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(changeView) userInfo:nil repeats:YES];
}
-(void)changeView{
[self performSegueWithIdentifier:@"splash" sender:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
顺便说一句,我正在使用 Storyboard,这是一个奇怪的错误,在我添加启动画面后一直出现在控制台中,我不知道如何摆脱它。
最佳答案
在身份检查器( Storyboard)中为 TabBarController 提供 Storyboard ID“TabBarViewController”
并实现 changeView 为-
-(void)changeView
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
TabBarViewController *tabBarViewController = [storyBoard instantiateViewControllerWithIdentifier:@"TabBarViewController"];
[[[[UIApplication sharedApplication] delegate] window] setRootViewController:tabBarViewController];
}
关于iphone - 谁的 View 不在窗口层次结构中!问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14380680/