ios - 在一个函数中以编程方式在彼此之上呈现两个 UIViewController

标签 ios swift uiviewcontroller uiimagepickercontroller presentviewcontroller

我正在尝试呈现 (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 and ImagePicker 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/

相关文章:

ios - CMTimeMake(持续时间,fps)。这是什么意思?

ios - SwiftUI View 不会在单独的 View 中更新

ios - subview 加载但没有一个按钮可以工作 ios swift

swift - 如何将 Int16 音频样本数据转换为浮点音频样本数组

ios - 如何通过自定义字段查找自定义 View

iphone开发: is it possible to extend more than one viewControllers?

ios - iOS XCode 模拟器的快照

iphone - 我如何在 ios 中使用 NSXMLParser 解析这个 xml?

ios - Shinobi Datagrid 滚动到特定行

ios - 在 UICollectionView 中显示错误的图像