Ios 在基于UIDocumentBrowserViewController的应用程序中打开多个文档
苹果的文档很少涉及基于Ios 在基于UIDocumentBrowserViewController的应用程序中打开多个文档,ios,mdi,document-based,Ios,Mdi,Document Based,苹果的文档很少涉及基于UIDocumentBrowserViewController的应用程序,这些应用程序希望支持同时打开多个文档 我希望启用此功能,以便用户可以轻松地在两个或多个文档之间复制/粘贴,而无需退出到文档浏览器,这在iOS上不是一种流畅的体验 除了对房产的简要描述外,我什么也找不到 对于单个文档视图,苹果建议使用模式视图,但没有说明其他内容 问题 实现多个打开文档的体验和UI的推荐方法是什么(如果有) 用户是否有办法打开一组文档,然后在打开现有文档的同时打开另一个文档 有没有实现这
UIDocumentBrowserViewController
的应用程序,这些应用程序希望支持同时打开多个文档
我希望启用此功能,以便用户可以轻松地在两个或多个文档之间复制/粘贴,而无需退出到文档浏览器,这在iOS上不是一种流畅的体验
除了对房产的简要描述外,我什么也找不到
对于单个文档视图,苹果建议使用模式视图,但没有说明其他内容
问题
我是一个相对较新的iOS开发人员,所以对所有这些都要谨慎对待 以下几点对我很有用:
URL
输入的ViewController,以及另一个可接受[URL]
输入的ViewController。然后,这些ViewController必须在屏幕上显示与URL关联的文档。
- 可以处理一个或多个文档的单个ViewController也可以工作
documentBrowser(:,didPickDocumentURLs:)
中,检查传入的URL
数量,并显示上述其中一个ViewController(视情况而定)class DocumentBrowserViewController: UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
allowsDocumentCreation = false
allowsPickingMultipleItems = true
// -snip-
}
// MARK: UIDocumentBrowserViewControllerDelegate
// -snip-
func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentURLs documentURLs: [URL]) {
if documentURLs.count < 1 {
return
} else if documentURLs.count == 1 {
presentDocument(at: documentURLs[0])
} else {
presentDocuments(at: documentURLs)
}
}
// -snip-
// MARK: Document Presentation
func presentDocument(at documentURL: URL) {
// present one document
// example:
// let vc = SingleDocumentViewController()
// vc.documentURL = documentURL
// present(vc, animated: true, completion: nil)
}
func presentDocuments(at documentURLs: [URL] {
// present multiple documents
// example:
// let vc = MultipleDocumentViewController()
// vc.documentURLs = documentURLs
// present(vc, animated: true, completion: nil)
}
}
类DocumentBrowserViewController:UIDocumentBrowserViewController,UIDocumentBrowserViewControllerDelegate{
重写func viewDidLoad(){
super.viewDidLoad()
代表=自我
allowsDocumentCreation=false
allowsPickingMultipleItems=true
//-剪断-
}
//标记:UIDocumentBrowserveWControllerDelegate
//-剪断-
func documentBrowser(u控制器:UIDocumentBrowserViewController,didpickdocumenturl:[URL]){
如果documentURLs.count<1{
返回
}如果documentURLs.count==1,则为else{
presentDocument(位于:documentURLs[0])
}否则{
presentDocuments(位于:documentURLs)
}
}
//-剪断-
//标记:文档演示
func presentDocument(位于documentURL:URL){
//提交一份文件
//例如:
//设vc=SingleDocumentViewController()
//vc.documentURL=documentURL
//当前(vc,动画:真,完成:无)
}
func presentDocuments(位于DocumentURL:[URL]{
//出示多份文件
//例如:
//设vc=MultipleDocumentViewController()
//vc.documentURLs=documentURLs
//当前(vc,动画:真,完成:无)
}
}
要回答您的其他问题,请执行以下操作:
- 如果选择了文件夹,且该文件夹不在应用程序自己的目录中,则应用程序将无权访问文件夹中的文档
documentBrowser(:,didpickdocumenturl:)
将被重命名为documentBrowser(:,didPickDocumentsAt:)
我是一个相对较新的iOS开发人员,所以对这一切都要谨慎对待
以下几点对我很有用:
URL
输入的ViewController,以及另一个可接受[URL]
输入的ViewController。然后,这些ViewController必须在屏幕上显示与URL关联的文档。
- 可以处理一个或多个文档的单个ViewController也可以工作
documentBrowser(:,didPickDocumentURLs:)
中,检查传入的URL
数量,并显示上述其中一个ViewController(视情况而定)class DocumentBrowserViewController: UIDocumentBrowserViewController, UIDocumentBrowserViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
allowsDocumentCreation = false
allowsPickingMultipleItems = true
// -snip-
}
// MARK: UIDocumentBrowserViewControllerDelegate
// -snip-
func documentBrowser(_ controller: UIDocumentBrowserViewController, didPickDocumentURLs documentURLs: [URL]) {
if documentURLs.count < 1 {
return
} else if documentURLs.count == 1 {
presentDocument(at: documentURLs[0])
} else {
presentDocuments(at: documentURLs)
}
}
// -snip-
// MARK: Document Presentation
func presentDocument(at documentURL: URL) {
// present one document
// example:
// let vc = SingleDocumentViewController()
// vc.documentURL = documentURL
// present(vc, animated: true, completion: nil)
}
func presentDocuments(at documentURLs: [URL] {
// present multiple documents
// example:
// let vc = MultipleDocumentViewController()
// vc.documentURLs = documentURLs
// present(vc, animated: true, completion: nil)
}
}
类DocumentBrowserViewController:UIDocumentBrowserViewController,UIDocumentBrowserViewControllerDelegate{
重写func viewDidLoad(){
super.viewDidLoad()
代表=自我
allowsDocumentCreation=false
allowsPickingMultipleItems=true
//-剪断-
}
//标记:UIDocumentBrowserveWControllerDelegate
//-剪断-
func documentBrowser(u控制器:UIDocumentBrowserViewController,didpickdocumenturl:[URL]){
如果documentURLs.count<1{
返回
}如果documentURLs.count==1,则为else{
presentDocument(位于:documentURLs[0])
}否则{
presentDocuments(位于:documentURLs)
}
}
//-剪断-
//标记:文档演示
func presentDocument(位于documentURL:URL){
//提交一份文件
//例如:
//设vc=SingleDocumentViewController()
//vc.documentURL=documentURL
//当前(vc,动画:真,完成:无)
}
func presentDocuments(位于DocumentURL:[URL]{
//出示多份文件
//例如:
//设vc=MultipleDocumentViewController()
//vc.documentURLs=documentURLs
//当前(vc,动画:真,完成:无)
}
}
要回答您的其他问题,请执行以下操作: