swift - UIImagePickerController 关闭不正确
问题描述
UITabbarController中有5个项目:VC0、VC1、VC3(默认选中)、VC4、VC5。
UITabbarController > NavigationController > VC1 > VC1-A
UIImagePickerController 在 VC1-A 中呈现:
let imagePickerController = UIImagePickerController()
imagePickerController.sourceType = .photoLibrary
imagePickerController.delegate = self
imagePickerController.allowsEditing = false
self.present(imagePickerController, animated: false)
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
let info = convertFromUIImagePickerControllerInfoKeyDictionary(info)
if let image = info[convertFromUIImagePickerControllerInfoKey(UIImagePickerController.InfoKey.originalImage)] as? UIImage{
topImage.image = image
}
picker.dismiss(animated: true, completion: nil)
}
When image is selected and the picker is dismissed, the view will go to the default selected item VC3, but not VC1-A.
我在 App 的重新测试中发现了这一点,但我记得它之前工作正常。我现在不记得我做了什么可能使它不正确,Xcode 更新,Swift 版本更新?我知道我在这部分没有做任何改变。
以下尝试也不起作用:
self.navigationController?.present(imagePickerController, animated: false)
self.navigationController?.dismiss(animated: true, completion: nil)
self.navigationController?.popViewController(animated: true)
picker.popViewController(animated: true)
现在我让它像这样工作:
picker.dismiss(animated: true, completion: {
self.tabBarController?.selectedIndex = 1
})
但是解决问题不是一个好主意,希望有人能给出一个适当的解决方案。谢谢。
解决方案
您应该获取 VC1-A 导航控制器的 tabBarController 并更改选定的索引
picker.dismiss(animated: true) {//dismiss image picker
if let navigationController = self.navigationController {
navigationController.popToRootViewController(animated: true)//go to VC1
navigationController.tabBarController?.selectedIndex = 2//go to VC3
}
}
推荐阅读
- cmake - cmake 的 OpenMPI 基目录的位置
- ruby-on-rails - 阶段中的 NoMethodError#edit
- javascript - 当用户单击推送通知时打开 TWA 应用程序而不是 Web 应用程序
- c++ - 函数模板返回类型
- c# - 如何在 postsharp 中使用 MultipleInheritance
- raku - Raku Native 调用 gtk-clipboard-request-text?
- java - 传递多个文件时,Swing 窗口卡住
- amazon-web-services - AWS:我们可以考虑为单个产品提供“多个 EC2 实例和 RDS”作为水平扩展吗?
- sql - 如何有条件地禁用 SQL 中的联接?
- android - 如何在最新版本的 Kotlin for android 中调用 1-6 之间的随机整数?