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
})
但这不是解决问题的好主意,希望有人能给出适当的解决方案。谢谢。
答案 0 :(得分:0)
您应该获取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
}
}