Search code examples
ios4mpmediapickercontroller

MPMediaPickerController selected index not working


I am implementing a MPMediaPickerController based application. In that When I tried to open music application it need to takes me to the "playlists" tab instead of showing "Music" tab. For this I used selected index property to make it. But still it doesn't work.

Following is my code:

   MPMediaPickerController *picker =
    [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

    picker.delegate                     = self;
    picker.allowsPickingMultipleItems   = YES;
    picker.prompt                       = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");

    // The media item picker uses the default UI style, so it needs a default-style
    //      status bar to match it visually
    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated: YES];
    picker.tabBarController.selectedIndex=1;
    [picker.tabBarController.selectedViewController viewDidAppear:YES];

    [self presentModalViewController: picker animated: YES];
    [picker release];

Solution

  • You cannot set the selected index of a MPMediaPickerController unfortunately. It's not a regular UITabBarController. If you want to change the selected index, color, etc, you'll have to subclass it. Sorry.

    Check http://bit.ly/krMNMK for more reference.