views:

86

answers:

1

I think the issue here is that I'm trying to call a mediaPicker and that doesn't support other orientations...

Does anyone have a fix for this?

Here is my current code:

- (IBAction)openMediaPicker:(id)sender {
    MPMediaPickerController *mediaPicker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
mediaPicker.delegate = self;
mediaPicker.allowsPickingMultipleItems = YES; // this is the default
    mediaPicker.modalPresentationStyle = UIModalPresentationPageSheet;
    //mediaPicker.prompt = @"Select items to play";
[self presentModalViewController:mediaPicker animated:YES];
[mediaPicker release];

    // Init a Navigation Controller, using the MediaPicker as its root view controller
    UINavigationController *theNavController = [[UINavigationController alloc] initWithRootViewController:mediaPicker];
    [theNavController setNavigationBarHidden:YES];

    // Init the Popover Controller, using the navigation controller as its root view controller
    popoverController = [[UIPopoverController alloc] initWithContentViewController:theNavController];

    // Make a rect at the size and location of the button I use to invoke the popover
   CGRect popOverRect = chooseMusicButton.frame;

    // Specify the size of the popover
    CGSize MySize = CGSizeMake(520.0, 720.0);

    [popoverController setPopoverContentSize:MySize animated:YES];

    // Display the popover
    [popoverController presentPopoverFromRect:popOverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    popoverController.delegate = self;
}
A: 

All pre-defined modal controllers support all orientations but they must be presented from the root view controller for them to behave correctly in orientation and rotation. My guess is that that the "self" in your code is not the root view controller. You may have to re-architect the code a bit to make this happen if possible.

There are other hacks I have seen to make it work without being presented from the root view controller but they all seemed to be asking for trouble such as extending UIViewController with a category to over-ride interfaceOrientation.

If you can present it from the root view controller, it would be the simplest and cleanest but I realize it is not always possible (e.g., it is inside a library you are providing to third party apps to embed).

Wings of Fancy
Odd. This code is in my root view controller :/
Alan Taylor
If self is indeed the root view controller, the problem could be the navigation bar getting the mediaPicker (not a root view controller) in its init as its root view controller. Change it to self from mediaPicker. Also make sure you don't confuse between a root view controller (there is only one in an application tied to the app delegate) and any controllers used as a parent of some other controllers in a controller hierarchy. The rotation and orientation logic only works at the topmost level and is not propagated through a controller hierarchy.
Wings of Fancy