ios 应用程序应该有一个根视图控制器控制台

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8190567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 15:28:55  来源:igfitidea点击:

applications expected to have a root view controller console

objective-ciosxcodeconsole

提问by Teddy13

I am getting a message within the console when I run my app that says:

当我运行我的应用程序时,我在控制台中收到一条消息:

2011-11-16 19:17:41.292 Juice[8674:707] Applications are expected to have a root view controller at the end of application launch

2011-11-16 19:17:41.292 Juice [8674:707] 在应用程序启动结束时,应用程序预计会有一个根视图控制器

I have heard from others that this has to do with the method didFinishLaunchingWithOptions

我听别人说这与方法有关 didFinishLaunchingWithOptions

If anyone has any suggestions for why I am getting this error, it would be much appreciated.

如果有人对我收到此错误的原因有任何建议,将不胜感激。

My code for the method:

我的方法代码:

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

    // Override point for customization after application launch.

    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];

    [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

    return YES;
}

回答by Kjuly

You should replace the

你应该更换

[window addSubview:tabBarController.view];

to

[self.window setRootViewController:tabBarController];

Maybe you built your project with 'Empty Application' and forgot to set the rootViewControllerin your didFinishLaunchingWithOptions(which exists in your AppDelegate.m).

也许您使用“ Empty Application”构建了您的项目,但忘记rootViewController在您的didFinishLaunchingWithOptions(存在于您的AppDelegate.m 中)中进行设置。

However, if you build your project with 'Single View Application' or some other type, the project will set the rootViewControllervia xibby default (which might be a MainWindow.xibin your project).

但是,如果您使用“单一视图应用程序”或其他类型构建项目,项目将默认设置rootViewController通孔xib(可能是项目中的MainWindow.xib)。

回答by Frank

I had the same problem on iOS 5, after adding a storyboard to an "empty" project. It turns out I had to remove all the lines in AppDelegate.m that set values to self.window.

在向“空”项目添加故事板后,我在 iOS 5 上遇到了同样的问题。事实证明,我必须删除 AppDelegate.m 中将值设置为self.window.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    //self.window.backgroundColor = [UIColor whiteColor];
    //[self.window makeKeyAndVisible];
    return YES;
}

回答by anja

If you have MainWindow.xib, make sure you set Main Interface in Target's summary to MainWindow.

如果您有 MainWindow.xib,请确保将 Target 摘要中的 Main Interface 设置为 MainWindow。

回答by coco

The way I got this error Applications are expected to have a root view controller at the end of application launchto disappear, was to ensure the loadViewmethod in my root view controller was calling [super loadView]. Hope this helps someone.

我让这个错误Applications are expected to have a root view controller at the end of application launch消失的loadView方法是确保我的根视图控制器中的方法正在调用[super loadView]. 希望这可以帮助某人。

回答by chown

Try using self.windowinstead of window(if your setup has windowbeing synthesizedwith something like @synthesize window=_window;):

尝试使用self.window,而不是window(如果你的安装有windowsynthesized喜欢的东西@synthesize window=_window;):

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

? ? // Override point for customization after application launch.

? ? [self.window addSubview:tabBarController.view];
? ? [self.window makeKeyAndVisible];

? ? [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];

? ? return YES;
}


2nd possibility:

第二种可能:

In your main.m make sure the last argument is the name of the App Delegate. In your case, it looks like it should be:

在 main.m 中,确保最后一个参数是 App Delegate 的名称。在您的情况下,它看起来应该是:

retVal = UIApplicationMain(argc, argv, nil, @"JuiceAppDelegate");


Solution:

解决方案:

As @marcus13 said in the comments below.. This was fixed was found in this SO answer: Applications are expected to have a root view controller at the end of application launch- by by moving the UIAlertViewmethods from -(void)viewDidLoadto -(void)viewDidAppear:(BOOL)animated

正如@marcus13 在下面的评论中所说的 .. 在这个 SO 答案中发现了这个问题:应用程序预计在应用程序启动结束时有一个根视图控制器- 通过将UIAlertView方法从-(void)viewDidLoad-(void)viewDidAppear:(BOOL)animated

回答by Rob Smythe

Another cause:

另一个原因:

I was in IB attaching File Owner to a new small ImageView I'd dragged onto the View. I hadn't called it an IBOutlet in the .h file, so when I ctrl-dragged to it, the new Imageview wasn't listed as a possible connection. The only possibility displayed in the little black box was View. I must have clicked, inadvertently. I made a few changes then ran the program and got the Root Controller error. The fix was reconnecting File Owner to the bottom View in the xib - IB screen.

我在 IB 中将文件所有者附加到我拖到视图上的一个新的小 ImageView。我没有在 .h 文件中称它为 IBOutlet,所以当我按住 ctrl 拖动到它时,新的 Imageview 没有被列为可能的连接。小黑框中显示的唯一可能是查看。我一定是无意中点击了。我做了一些更改然后运行程序并得到根控制器错误。修复是将文件所有者重新连接到 xib - IB 屏幕中的底部视图。

回答by schaermu

I just ran into this issue while building a new project from scratch. I added a StoryBoard and build my whole interface, but i did not select a template.

我刚刚在从头开始构建新项目时遇到了这个问题。我添加了一个 StoryBoard 并构建了我的整个界面,但我没有选择模板。

When doing it this way, you have to make sure of 3 main things:

这样做时,您必须确保 3 件主要事情:

Always select your initial controller (TabBarcontroller or NavigationController) as the initial view in your Storyboard.

始终选择初始控制器(TabBarcontroller 或 NavigationController)作为 Storyboard 中的初始视图。

Change the code in your Appdelegate.m from this

从此更改 Appdelegate.m 中的代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

to this

对此

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    return YES;
}

Check your [ProjectName]-Info.plist file. If there is no key named "Main storyboard file base name", you have to manually add it and set it's value to the name of your storyboard file (without the extension).

检查您的 [ProjectName]-Info.plist 文件。如果没有名为“主故事板文件基本名称”的键,则必须手动添加它并将其值设置为故事板文件的名称(不带扩展名)。

After i did all of these steps, my application ran perfectly.

完成所有这些步骤后,我的应用程序运行良好。

回答by blauzahn

I had the same problem with my App. It appeared when I added another view controller to my project and tried to set it as the root view controller in AppDelegate. I tried several solutions, but none of them could fix the problem. Finally I found the cause: I had two localized versions of the MainWindow.xib file (One for german and another for english localization). So I deleted the english file and reconnected the IBOutlets in MainView.xib. This solved the problem.

我的应用程序遇到了同样的问题。当我将另一个视图控制器添加到我的项目并尝试将其设置为 AppDelegate 中的根视图控制器时,它出现了。我尝试了几种解决方案,但没有一个可以解决问题。最后我找到了原因:我有两个 MainWindow.xib 文件的本地化版本(一个用于德语,另一个用于英语本地化)。所以我删除了英文文件并重新连接了 MainView.xib 中的 IBOutlets。这解决了问题。

回答by capikaw

I also had the same problem. All I got was a black screen. Turns out I had inadvertently removed:

我也有同样的问题。我得到的只是黑屏。原来我无意中删除了:

[self.window makeKeyAndVisible];

from my code. Hope this helps someone!

从我的代码。希望这可以帮助某人!

回答by Ray A

I'm not sure if this will help anybody else, but if you have used interface builder to create your mainWindow and have done all the linking between the delegate make sure you don't have the following code within application:didFinishLaunching ...

我不确定这是否对其他人有帮助,但是如果您使用界面构建器创建了 mainWindow 并完成了委托之间的所有链接,请确保您的应用程序中没有以下代码:didFinishLaunching ...

[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]

I was having the same error until I removed the above line. Hope that helps!

在删除上述行之前,我遇到了同样的错误。希望有帮助!

EDIT: Doing the above now has my viewControllers viewDidAppear method being called twice ?

编辑:现在执行上述操作使我的 viewControllers viewDidAppear 方法被调用两次?