Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Application's main window

UIApplication has a method keyWindow, however if an alert view is showing then this returns the window of the alert view and not the main window of the application.

How can I get the app's main window?

like image 828
Jonathan. Avatar asked Jul 24 '13 17:07

Jonathan.


People also ask

Which is the main window in Visual Basic?

The Main window is the main way to access other windows, load and save files, control trajectory playback, change various global program settings, access help, and to quit the program. Many of these actions can also be performed with the menu shortcut keys described in Table 5.3.

How do I change the startup window in WPF?

If you look at App. xaml class of your WPF application, you will see the following XAML code. Here the StartupUri sets the startup Window of an application. If you want to change the Startup window to some other window, just change this value.

How do you call a window in WPF?

In WPF we have a couple of options by using the Show() and ShowDialog() methods. Well, if you want to close the opened window when a new window gets open then you can use the Show() method: Window1 win1 = new Window1(); win1. Show(); win1.


2 Answers

The UIApplicationDelegate usually has a reference to the "main window":

[[[UIApplication sharedApplication] delegate] window]; 

Furthermore, UIApplication has an array of windows [[UIApplication sharedApplication] windows].

See the UIApplication Class Reference.

like image 95
Espresso Avatar answered Sep 20 '22 08:09

Espresso


I'm not 100% sure this works in every case but this should work:

UIWindow *mainWindow = [UIApplication sharedApplication].windows[0]; 

The windows are ordered back to front so the main window should always be at index 0.

like image 31
rmaddy Avatar answered Sep 21 '22 08:09

rmaddy