Search code examples
iphoneiosuinavigationcontrolleruiimagepickercontrolleruiwindow

iPhone - launching an UIImagePickerController from a UIWindow


How may I launch a UIImagePickerController from the main UIWindow (no view defined) from - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions, on a project for which the main window does not have a built-in Navigation controller into IB (and without having to add one into IB)?


Solution

  • If you don't need UINavigationController then just place regular UIViewController as a root view for main windows. And present UIImagePickerController from it.

    Example:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window.rootViewController = [[[UIViewController alloc] init] autorelease];
        UIImagePickerController *imagePickerController = [[[UIImagePickerController alloc] init] autorelease];
        [self.window.rootViewController presentModalViewController:imagePickerController animated:YES];
        [self.window makeKeyAndVisible];
        return YES;
    }