Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

springframework

macrumors member
Original poster
Mar 31, 2008
59
0
I know there is only one UIWindow object so there should be something like UIWindowInstance(); to retrieve it, allowing you to add views and get rid of views in whatever class you want.

so what is the way to get the UIWindow?
 

springframework

macrumors member
Original poster
Mar 31, 2008
59
0
Inside a class that extends UIView i can use self.window to get the window.

the instance of this class that i call self.window from is already added to the window. I am not sure if this would work before the instance is added to the window.


does anyone have a way of accessing the UIWindow from any class, without passing a reference to it or a reference to the class that created it?

I tried to make it a global variable but this didn't seem to work for me, maybe I just did it wrong?
 

Littleodie914

macrumors 68000
Jun 9, 2004
1,813
8
Rochester, NY
Sure! :)

There are two different ways to access the UIWindow objects currently being used by the application:

Code:
[[UIApplication sharedApplication] keyWindow]

This will return the currently "on top" window, (technically, the one that was most recently told to display itself) and is probably the only one you'll need for a simple application.

For anything more elaborate though, especially if you know you'll be using more than one window, you can use:

Code:
[[UIApplication sharedApplication] windows]

Which will return an NSArray containing all the UIWindow objects currently "owned" by the application. Happy coding! :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.