Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.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 使用DocumentInteractionControllerServiceControllerForpReview时显示白色UINavigationBar_Ios_Iphone_Swift_Download - Fatal编程技术网

Ios 使用DocumentInteractionControllerServiceControllerForpReview时显示白色UINavigationBar

Ios 使用DocumentInteractionControllerServiceControllerForpReview时显示白色UINavigationBar,ios,iphone,swift,download,Ios,Iphone,Swift,Download,我希望用户能够点击一个按钮,从互联网上查看文件。代码如下所示: func downloadFile(button: MyButton) { let cell = collectionView.cellForItemAtIndexPath(button.indexPath!) as! MyCollectionViewCell //Get documents directory URL let documentsDirectoryUrl = NSFileManager.d

我希望用户能够点击一个按钮,从互联网上查看文件。代码如下所示:

func downloadFile(button: MyButton) {
    let cell = collectionView.cellForItemAtIndexPath(button.indexPath!) as! MyCollectionViewCell

    //Get documents directory URL
    let documentsDirectoryUrl =  NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first

    let sourceUrl = NSURL(string:"https://download.com/file.pdf")!

    //Get the file name and create a destination URL
    let fileName = sourceUrl.lastPathComponent!
    let destinationURL = documentsDirectoryUrl!.URLByAppendingPathComponent(fileName)

    //Hold this file as an NSData and write it to the new location
    if let fileData = NSData(contentsOfURL: sourceUrl) {
        fileData.writeToURL(destinationURL, atomically: false)   // true

        let viewer = UIDocumentInteractionController(URL:destinationURL)
        viewer.delegate = self
        viewer.presentPreviewAnimated(true)
    }
}

func documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController) -> UIViewController {
    return self
}
在上述版本的代码中,我得到了两个错误:
对开始/结束外观转换的调用不平衡
找不到代理的预览项
,但是预览看起来与我想要的完全一样,尽管导航栏标题没有任何字体自定义(这很好)

阅读了这里的一些问题后,我决定尝试将
返回self
代码更改为
返回self.navigationController。这就像希望的那样删除了错误消息,但也意味着导航无法读取

我的UINavigationController以正常方式扩展,以设置背景颜色等:

class NavigationController : UINavigationController {
    override func viewDidLoad(){
        super.viewDidLoad()
        self.navigationBar.barTintColor = UIColor.purpleColor()
        self.navigationBar.tintColor = UIColor.whiteColor()
        self.navigationBar.setBackgroundImage(UIImage(), forBarPosition: UIBarPosition.Any, barMetrics: UIBarMetrics.Default)
如果我对setBackgroundImage行进行注释,我可以看到预期的所有内容,但是barTintColor明显略有变化-我不知道这是因为缺乏透明度支持还是其他原因?这是迄今为止最大的努力,但是颜色的变化让我很恼火!它也成为现有导航堆栈的一部分,而不是像返回ViewController而不是NavigationController时那样显示为弹出窗口

有没有一种方法可以1)以弹出方式(可能使用定制的导航控制器)实现这一点,或者2)修复背景颜色的变化。非常感谢