UIImagePickerController 关闭不正确
UIImagePickerController dismiss not properly
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)
}
选择映像并取消了选择器时,该视图将转到默认选定的项目VC3,而不是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
}
}
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)
}
选择映像并取消了选择器时,该视图将转到默认选定的项目VC3,而不是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
}
}