I'm creating a ios application without nib files and want to initialize the window in the application delegate like so:
CGRect screenBounds = [[UIScreen mainScreen] bounds];
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
self.window.backgroundColor = [UIColor greenColor];
NSLog(@"%@", self.window.bounds);
The window shows up and I can see the green color I defined. When I debug self.window I get to see the bounds of the frame I just defined but when I want to access the bounds property, it returns null. Same with frame. What's the difference?
When I want to initialize a view next, it won't work because the frame/bounds are not defined to init that view:
// create root view
RootView* rootView = [[[RootView alloc] initWithFrame:self.window.bounds] autorelease];
What am I doing wrong?
Yea, this is not going to work
NSLog(@"%@", self.window.bounds);
The window's bounds are not an object so %@ can't be used to display it :)
Try converting the CGRect into an NSString * first :
NSLog(@"%@", NSStringFromCGRect(self.window.bounds));
That should give you a bit more debugging information to help you solve your problem :)
NB %@ simply calls description for the object and displays that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With