所以我在导航 Controller 内,想在按下按钮时显示一个图像选择器。这很好用,但是当我关闭选择器时,它会将我扔回 Root View Controller ,而不是我想要处理图像的地方。
这是我的代码:
@IBAction func attachPhotoButtonPressed(sender: UIButton) {
imagePicker.sourceType = .SavedPhotosAlbum
presentViewController(imagePicker, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
print("Success")
} else{
print("Something went wrong")
}
self.dismissViewControllerAnimated(true, completion: nil)
}
我已经查看了这些问题,但没有找到解决方法。 (不是 Objective-C 的家伙)
Pushing a navigation controller is not supported- performing segues
presenting ViewController with NavigationViewController swift
Pushing a navigation controller is not supported
你跳到 Root View Controller 的原因是因为这条线
self.dismissViewControllerAnimated(true, completion: nil)
正在关闭父 View (自身),而不是选择器 View 。因此,假设您有对选择器的引用,那么您应该调用
picker.dismissViewControllerAnimated(true, completion: nil)
关于ios - NavigationController 中的 Swift ImagePicker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44467079/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |