我可以看到歌曲列表并选择歌曲。但是我不能在按下“完成”时忽略视图控制器。我已经尝试过PresentViewController,因为不推荐使用Modal控制器。
- (IBAction) showMediaPicker: (id) sender {
picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeAnyAudio];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = NSLocalizedString (@"AddSongsPrompt", @"Prompt to user to choose some songs to play");
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated:YES];
[self.picker removeFromParentViewController];
[self presentViewController:picker animated:YES completion:nil];
// [picker release];
}
// Responds to the user tapping Done after choosing music.
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection {
[self.picker removeFromParentViewController];
[self dismissViewControllerAnimated:YES completion:nil];
//
[self.delegate updatePlayerQueueWithMediaCollection: mediaItemCollection];
// [self.mediaItemCollectionTable reloadData];
// [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackOpaque animated:YES];
}
我也尝试过RemovefromSuperview,似乎没什么用。我正在iPhone 6模拟器和带iOS 8.1.3的iPhone 5上进行测试。
任何???
答案 0 :(得分:0)
我测试了您的代码并删除了对removeFromParentViewController:
的一些电话,因为我认为他们并不是必需的。
- (IBAction)showMediaPicker:(id)sender {
MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes:MPMediaTypeAnyAudio];
picker.delegate = self;
picker.allowsPickingMultipleItems = YES;
picker.prompt = @"Some Prompt";
[self presentViewController:picker animated:YES completion:nil];
}
// mediaPicker:didPickMediaItems: will be called if at least one song was selected
- (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
[mediaPicker dismissViewControllerAnimated:YES completion:nil];
}
// mediaPickerDidCancel: will be called if no songs were selected
- (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker {
[mediaPicker dismissViewControllerAnimated:YES completion:nil];
}
确保您的.h
- 文件包含MPMediaPickerControllerDelegate
协议。