我的 UITabBarController
中有 4 个选项卡,我在我的 tabBar 中显示来自第 4 个 ViewController 的 UIImagePickerController
。 (所有选项卡 viewControllers 都嵌入在 UINavigationController
中)
当我的 UIImagePickerController
从我的第 4 个选项卡中消失时,无论是在选择图像之后还是只是取消选择器,它都会将我带回到我的第一个选项卡(0 索引)。
它应该保留在我的第 4 个选项卡 viewController 中。为什么会这样?我搜索了所有代码,但没有提到 tabBarController.setSelectedIndex = 0;
这是我用来呈现 UIImagePickerController
并关闭它的代码:
- (void)takeNewPhotoFromCamera
{
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.allowsEditing = NO;
//controller.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
controller.delegate = self;
[self presentViewController: controller animated: YES completion: nil];
}
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
}
请帮忙。
谢谢!
最佳答案
刚刚通过将图像选择器的 modalPresentationStyle
设置为 OverCurrentContext
找到了解决方案:
UIImagePickerController *controller = [[UIImagePickerController alloc] init];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.allowsEditing = NO;
controller.delegate = self;
controller.modalPresentationStyle = UIModalPresentationOverCurrentContext; //This is the magical line
[self presentViewController: controller animated: YES completion: nil];
关于ios - 关闭 UIImagePickerController 将 UITabBarController 重置为 0 索引 - iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37509025/