Anyone help me this error. Thank you very much

#1

I’ve followed the manual, but this error, please help me fix it
"‘NSInternalInconsistencyException’, reason: ‘Application windows are expected to have a root view controller at the end of application launch’"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; CGRect firstFrame = CGRectMake(160, 200, 200, 400); BNRHynosisView *firstView = [[BNRHynosisView alloc] initWithFrame:firstFrame]; firstView.backgroundColor = [UIColor greenColor]; [self.window addSubview:firstView]; [self.window setBackgroundColor:[UIColor whiteColor]]; [self.window makeKeyAndVisible]; return YES; }
but when I perform this way, then this line " CGRect firstFrame = CGRectMake(500, 700, 300, 400);" is not shown, it set CGRectMake(0, 0, 300, 400)

[code]- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController = [[UIViewController alloc] init];
self.window.rootViewController = viewController;
CGRect firstFrame = CGRectMake(500, 700, 300, 400);
BNRHynosisView *firstView = [[BNRHynosisView alloc] initWithFrame:firstFrame];
firstView.backgroundColor = [UIColor greenColor];
[self.window addSubview:firstView];
[self.window setBackgroundColor:[UIColor whiteColor]];
[self.window makeKeyAndVisible];
return YES;

}[/code]
Thanks for help.

#2

[quote][code]- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController = [[UIViewController alloc] init];
self.window.rootViewController = viewController;
CGRect firstFrame = CGRectMake(500, 700, 300, 400);
BNRHynosisView *firstView = [[BNRHynosisView alloc] initWithFrame:firstFrame];
firstView.backgroundColor = [UIColor greenColor];
[self.window addSubview:firstView];
[self.window setBackgroundColor:[UIColor whiteColor]];
[self.window makeKeyAndVisible];
return YES;

}[/code][/quote]
Because you have installed a root view controller, you need to insert your custom view into the view hierarchy of the root view controller.

So don’t do this:

[self.window addSubview:firstView];

but do this:

[viewController.view addSubview:firstView];
#3

Firstly thank ibex10. you are very enthusiastic. I’m done according to page 100, but when running my results are not like in the book. it looks like this

I do not know why? I’m a newbie.

#4

You need to set the bounds of your custom view to the size you want.

By setting the bounds of a view, not only can you change its size but you can also position it anywhere in its superview.

You can learn more about views by reading the following guide:

View Programming Guide for iOS: developer.apple.com/library/ios … 03-CH1-SW2

#5

Thank you. :stuck_out_tongue: