根据教程iOS Programming来的,教程所用的x-code版本比较低是X-code 4.3,适用于iOS5.我用的版本是X-Code6.1
过程如下:
先创建一个UIView的子类Hypnosister ,然后创建一个empty-application,再在AppDelegate中导入A类,在application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}方法中如下:
//
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
CGRect viewFrame = CGRectMake(160, 240, 100, 150);
Hypnosister *view = [[Hypnosister alloc] initWithFrame:viewFrame];
[view setBackgroundColor:[UIColor blackColor]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
//运行,白屏,同时控制台提示:Application windows are expected to have a root view controller at the end of application launch,不过书中表示这个提示可以忽略,关键是模拟器白屏啊~ -_-!
啊…… 目前为止没看出window和你创建的view有什么联系…… 所以白屏应该是正常的吧……
感觉你漏掉了一句: