【发布时间】:2011-10-16 06:40:21
【问题描述】:
升级到 xCode 4.2 后,我收到以下警告...
应用程序在应用程序启动结束时应该有一个根视图控制器
在网上阅读了关于 RootViewController 的所有内容后,我不确定我是否正确创建了根视图控制器。很久以前,当我第一次学习在 xCode 中编程时,我创建了它。
我有一个问题,可以将根视图控制器命名为 RootViewController 以外的名称。我现在看到的每个示例都将其命名为 RootViewController。我还看到它像这样在应用程序委托中合成...
@synthesize rootViewController = _rootViewController;
我不明白这是在做什么。为什么不只是...
@synthesize rootViewController;
无论如何,我将根视图控制器的名称更改为 RootViewController,并按照我在 cupsofcocoa.com 找到的示例进行操作。但即使在更改之后,我仍然收到“......预计会有一个根控制器......”警告。
如果有人有时间看看并告诉我我缺少什么,我在下面列出了我的初始化代码的重要部分。
谢谢,
约翰
//RootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController {
}
@end
.
//RootViewController.m
#import "RootViewController.h"
#import "JetLoggerAppDelegate.h"
@implementation RootViewController
@end
.
//JetLoggerAppDelegate.h my app delegate
#import <UIKit/UIKit.h>
@class RootViewController;
@interface JetLoggerAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
RootViewController *rootViewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet RootViewController *rootViewController;
@end
.
//.m app delegate
#import "JetLoggerAppDelegate.h"
#import "RootViewController.h" //I don't think I need this here
@implementation JetLoggerAppDelegate
@synthesize window;
@synthesize rootViewController = _rootViewController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if ([launchOptions count] == 0) {
_rootViewController = [[RootViewController alloc] init];
self.window.rootViewController = self.rootViewController;
[window makeKeyAndVisible];
return YES;
}else{
[JLHelper showAlertWithTitle:@"" message:[NSString stringWithFormat:@"launchOptions: %@", launchOptions]];
}
return NO;
}
.
//main.m
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"JetLoggerAppDelegate");
[pool release];
return retVal;
}
【问题讨论】:
标签: iphone xcode uiviewcontroller root