ios - 关闭 UIImagePickerController 将 UITabBarController 重置为 0 索引 - iOS

标签 ios objective-c uitabbarcontroller uiimagepickercontroller presentmodalviewcontroller

我的 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/

相关文章:

objective-c - UIPopoverController 顶部的按钮

objective-c - 仅在第二次加载 View 时运行函数

ios - Swift 选项卡栏已隐藏但自定义按钮仍处于事件状态

objective-c - 有什么方法可以读取Settings.app中的设置值?

ios - 排队 CAAnimations 时出现故障

ios - 从同一组件调用时,两个 IBAction 的触发顺序是什么?

ios - 无法将类型 '__NSDictionaryM' (0x2819d60) 的值转换为 'NSString' (0x2e85588)

ios - 在尝试使用另一个类时将类对象引用传递给另一个类不起作用

ios - 更改 "More"选项卡下的选项卡栏图标和表格背景的颜色?

ios - 即使有较新的固定 podspec 可用,pod lib lint 也会因循环依赖而失败