Ios &引用;在应用程序启动结束时,应用程序预计会有一个根视图控制器;
我的应用程序今天早些时候启动的很好,现在我遇到了这个错误 “在应用程序启动结束时,应用程序应具有根视图控制器” 我看过其他线程说要更改我的代码,但我从未更改任何代码来达到这一点 h代表Ios &引用;在应用程序启动结束时,应用程序预计会有一个根视图控制器;,ios,launching-application,Ios,Launching Application,我的应用程序今天早些时候启动的很好,现在我遇到了这个错误 “在应用程序启动结束时,应用程序应具有根视图控制器” 我看过其他线程说要更改我的代码,但我从未更改任何代码来达到这一点 h代表 @interface halo4AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>{ UIWindow *window; UITabBarController *tabBarControl
@interface halo4AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>{
UIWindow *window;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
my FirstViewController的xib是titles FirstView.xib,ext这不是错误,更像是警告 在您的应用程序委托中,有一个名为
application:didFinishLaunchingWithOptions:
的方法。在此方法中,您必须在方法self.window.rootViewController=[Some UIViewController]
同样,这不是错误,如果您有其他方法创建此rootViewController,则可以忽略rootViewController
编辑
您的方法应该是这样的:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
我的问题是,当我在iOS模拟器中运行应用程序时,启动屏幕会显示一个黑屏,然后什么也没有发生。你能发布
应用程序:didfishlaunchingwithoptions:
?-(BOOL)应用程序:(UIApplication*)应用程序didfishlaunchingwithoptions:(NSDictionary*)启动选项吗,对不起打扰你了。为什么这些改变是必要的。几小时前一切都很正常,你能提供更多关于代码的细节吗?比如在github上发布,或者对重要的类做一个要点。为了帮助您,我需要更多信息,比如您想要开始使用的控制器等等。我在那里看到了一些问题。首先,您从未设置窗口大小self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]代码>,第二,您永远不会实例化选项卡栏上的控制器UIViewController*viewController1=[[firstviewcontrolleralloc]initWithNibName:@“FirstViewController”bundle:nil]代码>和UIViewController*viewController2=[[secondviewcontrolleralloc]initWithNibName:@“SecondViewController”bundle:nil]代码>,第三,不使用self.tabBarController=[[UITabBarController alloc]init]启动选项卡栏
最后只需将控制器添加到选项卡栏[self.tabBarController setViewControllers:[NSArray arrayWithObjects:viewController1,viewController2,nil]代码>在所有这些之后,您添加了以前的代码睡眠(3)
self.window.rootViewController=self.tabBarController代码>[self.window makeKeyAndVisible]代码>返回是代码>我对这个很陌生,你介意告诉我这个代码需要去哪里,或者帮我把它放在代码里吗。顺便问一下,我有什么办法可以给你声誉或类似的东西吗?谢谢你的帮助
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}