Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWindow bounds/frame is null

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?

like image 992
Jovan Avatar asked Apr 02 '26 17:04

Jovan


1 Answers

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.

like image 183
deanWombourne Avatar answered Apr 04 '26 07:04

deanWombourne