【发布时间】:2015-09-17 07:45:34
【问题描述】:
这是在主菜单上使用的代码,当用户按下播放键时,当显示该屏幕时 (ViewController.m) 会显示错误
警告:尝试呈现不在窗口层次结构中的视图!
-(IBAction)play:(id)sender
{
if(IS_IPAD)
{
ViewController *view_obj = [[ViewController alloc]initWithNibName:@"ViewController_iPad" bundle:[NSBundle mainBundle]];
[self presentViewController:view_obj animated:YES completion:nil];
}
else if ([AISGlobal isIphone5thGeneration])
{
ViewController *view_obj = [[ViewController alloc]initWithNibName:@"ViewController_iPhone5" bundle:[NSBundle mainBundle]];
[self presentViewController:view_obj animated:YES completion:nil];
}
else
{
ViewController *view_obj = [[ViewController alloc]initWithNibName:@"ViewController_iPhone" bundle:[NSBundle mainBundle]];
[self presentViewController:view_obj animated:YES completion:nil];
}
}
在 AppDelegate.m 文件中,它会在“didFinishLaunchingWithOptions”部分显示此内容;
if(IS_IPAD)
{
self.start_screen_obj = [[Start_screen alloc] initWithNibName:@"Start_screen" bundle:nil];
}
else if ([AISGlobal isIphone5thGeneration])
{
self.start_screen_obj = [[Start_screen alloc] initWithNibName:@"Start_screen_iphone5" bundle:nil];
}
else
{
self.start_screen_obj = [[Start_screen alloc] initWithNibName:@"Start_screen_iphone" bundle:nil];
}
self.start_screen_obj.view.multipleTouchEnabled = YES;
self.window.rootViewController = self.start_screen_obj;
[self.window makeKeyAndVisible];
【问题讨论】:
-
错误解释了到底发生了什么。您正在从当前不属于视图层次结构的 UIViewController 将 UIViewController 呈现到视图层次结构上。您没有发布足够的上下文,我们无法帮助您调试问题。
-
我正在从 ViewController.m 文件中启动无法呈现的方法,当用户在开始屏幕上按下 Play 时会呈现该文件,我看不到哪里可以放置它,如果我当用户按下播放时尝试这样做,它仍然会出现同样的问题?
标签: ios objective-c iphone