I would like to know if there is a simple way to access the main window or view in IOS. Something similar to:
[UIScreen mainScreen]
Thank you.<
Simply clever, works from any class:
[(YourAppDelegate *)[[UIApplication sharedApplication] delegate] window];
Note: don't forget to import your appDelegate class
If you have a pointer to some subview in the window, you can easily access its window:
UIWindow *window = mySubview.window;
The main window is best found using UIWindow * mainWindow = [UIApplication sharedApplication].windows.firstObject;
Using keyWindow
can return a keyboard or UIAlertView window, which lie above your application window.
Try :
UIWindow *frontWindow = [[[UIApplication sharedApplication] windows]
lastObject];
or simply :
UIWindow *frontWindow = [[UIApplication sharedApplication] keyWindow];