Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在屏幕上创建一个取消按钮来选择Swift5上的文件?_Ios_Swift_File_Document - Fatal编程技术网

Ios 如何在屏幕上创建一个取消按钮来选择Swift5上的文件?

Ios 如何在屏幕上创建一个取消按钮来选择Swift5上的文件?,ios,swift,file,document,Ios,Swift,File,Document,我正在使用UIDocumentBrowser检索文件。但我无法在导航栏中放置“后退”或“取消”按钮 我想做一个取消按钮,但我不能做一个取消按钮。我怎样才能解决这个问题 当前代码 导入基础 导入UIKit @可用(iOS 11.0,*) 类DocumentBrowserViewController:UIDocumentBrowserViewController、UIDocumentBrowserViewControllerDelegate{ 重写func viewDidLoad(){ super.

我正在使用UIDocumentBrowser检索文件。但我无法在导航栏中放置“后退”或“取消”按钮

我想做一个取消按钮,但我不能做一个取消按钮。我怎样才能解决这个问题

当前代码

<代码>导入基础 导入UIKit @可用(iOS 11.0,*) 类DocumentBrowserViewController:UIDocumentBrowserViewController、UIDocumentBrowserViewControllerDelegate{ 重写func viewDidLoad(){ super.viewDidLoad() 代表=自我 browserUserInterfaceStyle=.dark view.tintColor=.white } func documentBrowser(uController:UIDocumentBrowserViewController,didRequestDocumentCreationWithHandler importHandler:@escaping(URL?,UIDocumentBrowserViewController.ImportMode)->Void){ 让newDocumentURL:URL?=nil //在此处设置新文档的URL。或者,您可以在调用importHandler之前显示模板选择器。 //确保始终调用importHandler,即使用户取消了创建请求。 如果newDocumentURL!=nil{ importHandler(新文档URL、.move) }否则{ importHandler(无,.none) } } func documentBrowser(u控制器:UIDocumentBrowserViewController,didpickdocumenturl:[URL]){ guard let sourceURL=documentURLs.first-else{return} 做{ 尝试presentDocument(位于:sourceURL) }抓住{ Log.Debug(“\(错误)”) } } func documentBrowser(uController:UIDocumentBrowservicewController,DIDMimportDocumentat sourceURL:URL,toDestinationURL destinationURL:URL){ //显示新创建文档的文档视图控制器 做{ 尝试presentDocument(位于:sourceURL) }抓住{ Log.Debug(“\(错误)”) } } func documentBrowser(uController:UIDocumentBrowservicewController,导入文档失败文档URL:URL,错误:错误?){ //确保正确处理失败的导入,例如,向用户显示错误消息。 } func presentDocument(位于documentURL:URL)抛出{ guard documentURL.startAccessingSecurityScopedResource()其他{ 抛出IXError.fileAcessFailed } let storyBoard=UIStoryboard(名称:“Main”,捆绑包:nil) 让documentViewController=storyBoard.InstanceEviewController(标识符为:“ViewController”)作为!ViewController documentViewController.document=文档(文件URL:documentURL) } } 我想要的取消按钮的图片

帮我大忙


提前感谢。

我是否正确理解您希望在导航堆栈上按一个viewController(documentViewController),并在导航栏上有一个返回按钮,将您引导回主viewController(DocumentBrowserViewController)?如果是这样,首先需要将documentViewController推送到当前导航堆栈上

首先,documentViewController是否出现

我看到的是,您实例化了一个documentViewController,将它的document设置为document(…),然后故事就结束了。我不使用故事板,但实例化视图控制器吗

如果你提供更多细节,我会更新答案。但总的结论是在您当前的文档中(…),您需要:

self.navigationController?.pushViewController(documentViewController, animated: true)

我了解了UIDocumentBrowserViewController类,并成功地添加了按钮。但是按钮的位置不是我想要的位置

但这已经解决了我的基本问题,所以我将结束这个问题

override func viewDidLoad(){
super.viewDidLoad()
代表=自我
allowsDocumentCreation=false
allowsPickingMultipleItems=false
browserUserInterfaceStyle=.dark
view.tintColor=.white
let cancelbutton=UIBarButtonim(标题:“取消”,样式:。普通,目标:自我,操作:#选择器(cancelbutton(发件人:))
additionalTrailingNavigationBarButtonItems=[cancelbutton]
}
@objc func取消按钮(发送方:UIBarButtonim){
驳回(动画:真,完成:无)
}

我不明白你的意思,因为我不懂Swift和iOS的语言。我把这个代码放在哪里?我通过插入我想要的图片编辑了这个问题。我当前的功能是选择文件并导航到代码中的视图控制器屏幕。该功能没有问题,但进入文件选择屏幕时没有取消按钮。