0

我的应用程序今天早些时候启动良好,现在我收到此错误

“应用程序在应用程序启动结束时应该有一个根视图控制器”

我看过其他线程说要更改我的代码,但我从未更改任何代码来达到这一点。

代表.h

@interface halo4AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate>{
    UIWindow *window;
    UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

代表.m

@implementation halo4AppDelegate

@synthesize window;
@synthesize tabBarController;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{   
    sleep(3);
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}


#pragma mark -
#pragma mark Memory management

- (void)dealloc {
    [tabBarController release];
    [window release];
    [super dealloc];
}

@end

我 FirstViewController 的 xib 是 Titles FirstView.xib , ext

4

1 回答 1

1

这不是错误,更像是警告。

在您的应用程序委托中有一个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;
}
于 2012-07-11T00:34:09.120 回答