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

时间:2012-07-11 00:28:44

标签: ios launching-application

我的应用程序今天早些时候推出正常,现在我收到此错误

  

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

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

Delegate.h

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

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

@end

Delegate.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是标题FirstView.xib,ext

1 个答案:

答案 0 :(得分: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;
}