实现功能
通过下面的代码,需要在iOS设备屏幕的一角中显示文本“hellow xcode”:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.NSLog(@"程序正在进入前台");self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];UILabel *myMessage;myMessage = [[UILabel alloc] initWithFrame:CGRectMake(30.0, 50.0, 300.0, 500.0)];myMessage.font = [UIFont systemFontOfSize:48];myMessage.text = @"hellow xcode";myMessage.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];[self.window addSubview:myMessage];self.window.backgroundColor = [UIColor whiteColor];[self.window makeKeyAndVisible];return YES;
}
出现错误
2015-12-05 15:07:10.210 iOSCase[1410:579208] *** Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3512.29.5/UIApplication.m:3299
2015-12-05 15:07:10.215 iOSCase[1410:579208] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'
*** First throw call stack:
(0x183c50f48 0x198803f80 0x183c50e18 0x184b44a1c 0x18948c414 0x189488f50 0x18da6f7c4 0x18da6fb44 0x183c08544 0x183c07fd8 0x183c05cd8 0x183b34ca0 0x1892521c8 0x18924cffc 0x100070814 0x1990528b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
错误原因
把didFinishLaunchingWithOptions中的代码全部放在.m和.h文件中,只留下return YES;