如何使用Swift在QLPreviewController中隐藏共享按钮? [英] How to hide share button in QLPreviewController using swift?
问题描述
我正在使用以下代码使用QLPreviewcontroller在我的应用程序中显示一些文档,
I'm using the below code to use QLPreviewcontroller to show some documents in my app,
let ql = QLPreviewController()
ql.dataSource = self
//ql.navigationItem.rightBarButtonItems = nil
ql.navigationItem.rightBarButtonItem = nil
presentViewController(ql, animated: true, completion: nil)
我不希望QLPreviewcontroller右上方的共享按钮.我尝试将rightBarButtonItem
设置为nil,但是它不起作用.
I don't want the share button in the right top of QLPreviewcontroller. I'd tried setting rightBarButtonItem
to nil, but it's not working.
我怎么藏起来?
推荐答案
在 iOS 10的Swift 3 中,这些解决方案都不对我有用.问题是共享按钮是在viewDidAppear方法之后创建的.
None of those solutions worked for me in Swift 3 for iOS 10. The issue is that the Share button is created after viewDidAppear method.
以下是我删除共享按钮的步骤:
Here are the steps I followed to remove the share button :
1)继承了我的QLPreviewController
1) Subclassed my QLPreviewController
2)创建了一个方法来打开此子类中的文档:
2) Created a method to open my document in this subclass :
func show(controller: UIViewController, url: NSURL) {
// Refreshing the view
self.reloadData()
// Printing the doc
if let navController = controller.navigationController {
navController.pushViewController(self, animated: true)
}
else {
controller.show(self, sender: nil)
}
}
3)在我的viewDidLayoutSubviews中,我创建了一个虚拟按钮项来替换共享按钮:
3) In my viewDidLayoutSubviews, I created a dummy button item to replace the share button :
override func viewDidLayoutSubviews() {
navigationItem.rightBarButtonItems?[0] = UIBarButtonItem()
}
4)当我想在另一个VC中打开文档时,我这样称呼它:
4) When I want to open a document in another VC, I call it like this :
QLSubclass().show(controller: self, url: path as NSURL)
注意:请始终以这种方式进行调用,而不要使用您实例化的全局变量,因为共享按钮消失之前,您总会看到它.
这篇关于如何使用Swift在QLPreviewController中隐藏共享按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!