我正在尝试呈现 (1) ScrollViewController
,然后在呈现之后呈现 (2) ImagePicker
。但是,仅显示 ScrollViewController
,之后不显示 ImagePicker
。
就个人而言,下面的代码工作正常,只是当一个跟随另一个时,它不起作用。我试过在完成处理程序中包含一个,仍然没有成功。
没有错误显示,除了,当序列发生时,Xcode 调试区域显示但完全空白,没有错误消息或警告。
问题:
What exactly is going on here that I'm missing? Why aren't both being presented? How can I ensure both the
ScrollViewController
andImagePicker
are displayed, one after the other?
(1) ScrollView Controller :
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ScrollViewControllerID") as! ScrollViewController
self.presentViewController(vc, animated: true, completion: nil)
(2) 图片选择器:
let imagePicker = MyImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .PhotoLibrary
imagePicker.allowsEditing = false
imagePicker.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
self.presentViewController(imagePicker, animated: true, completion: nil)
最佳答案
View Controller 一次只能呈现一个呈现的 Controller 。事实上,有一个属性:presentedViewController: UIViewController?
暗示了这一点。协调这些行动:
一个。仅展示您的基本 VC 中的第一个 VC。
B.在第一个演示调用的完成处理程序中,让第二个 VC 显示最上面的最后一个:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ScrollViewControllerID") as! ScrollViewController
self.presentViewController(vc, animated: true) {
let imagePicker = MyImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .PhotoLibrary
imagePicker.allowsEditing = false
imagePicker.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
vc.presentViewController(imagePicker, animated: true, completion: nil)
}
关于ios - 在一个函数中以编程方式在彼此之上呈现两个 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39175420/