草庐IT

ios - QLPreviewController 适用于 iOS 6;不在 iOS 7 上

coder 2024-01-20 原文

我查看了有关 QLPreviewController 在特定条件下无法工作的其他帖子。这个让我受阻:

RHBlobCollectionRHBlobView 是模型/ View 对象,分别保存提前缓存的集合和单个可显示文件。

RHBlobView.m:

    - (IBAction) handleBlobTap:(UITapGestureRecognizer *)sender
    {
        QLPreviewController *previewController = [[QLPreviewController alloc] init];

        // view tag is index in array of blobs
        [previewController setCurrentPreviewItemIndex:self.tag];

        // blobContainer is type RHBlobCollection
        [previewController setDataSource:self.blobContainer];

        UINavigationController *navController = (UINavigationController *)[[[[UIApplication sharedApplication] delegate] window] rootViewController];
        [navController pushViewController:previewController animated:YES];

    }

RHBlobCollection.m:

    - (NSInteger) numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
    {
        return [self.blobs count];
    }

    - (id <QLPreviewItem>) previewController:(QLPreviewController *)controller
                          previewItemAtIndex:(NSInteger)index
    {
        RHBlobView *blob = self.blobs[(NSUInteger) index];

        NSURL *fileURL = [RHCacheManager cachedFileURLForFilename:blob.filename withKey:blob.blobID];

        // URL proper?
        BOOL __unused proof1 = [fileURL isFileURL];

        // QLPreviewController can stomach it?
        BOOL __unused proof2 = [QLPreviewController canPreviewItem:fileURL];

        // Cached file actually exists?
        NSString *proof3path = [[fileURL resourceSpecifier] stringByReplacingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];
        BOOL __unused proof3 = [[NSFileManager defaultManager] fileExistsAtPath:proof3path];

        // Unless we're dealing with thumbnails, we're done. Return the URL of the resource.
        if ( ! [blob hasThumbnails] )
        {
            return fileURL;
        }

        // Process thumbnails into .pdf file for display...

proof1proof2proof3 都返回YESQLPreviewController 被拉出到一个单独的概念验证项目中,它按照预期的方式工作。不过,在我的完整应用程序项目中,它可以在 iOS 6 下运行,但在 iOS 7 下卡在“正在加载...”并带有微调器。

我的直觉告诉我,它应该与格式错误的文件 URL 或路径有关,但我的小测试显示一切都是共 enzyme 。还有其他人遇到过这个问题吗?

最佳答案

我同意 6 下 previewItemAtIndex 索引 > 0 而无论计数如何,7 索引始终为 -1 你能证实吗?

关于ios - QLPreviewController 适用于 iOS 6;不在 iOS 7 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19032418/

有关ios - QLPreviewController 适用于 iOS 6;不在 iOS 7 上的更多相关文章

  1. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  2. ruby-on-rails - form_for 中不在模型中的自定义字段 - 2

    我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢

  3. Ruby Sinatra 配置用于生产和开发 - 2

    我已经在Sinatra上创建了应用程序,它代表了一个简单的API。我想在生产和开发上进行部署。我想在部署时选择,是开发还是生产,一些方法的逻辑应该改变,这取决于部署类型。是否有任何想法,如何完成以及解决此问题的一些示例。例子:我有代码get'/api/test'doreturn"Itisdev"end但是在部署到生产环境之后我想在运行/api/test之后看到ItisPROD如何实现? 最佳答案 根据SinatraDocumentation:EnvironmentscanbesetthroughtheRACK_ENVenvironm

  4. ruby - 当使用::指定模块时,为什么 Ruby 不在更高范围内查找类? - 2

    我刚刚被困在这个问题上一段时间了。以这个基地为例:moduleTopclassTestendmoduleFooendend稍后,我可以通过这样做在Foo中定义扩展Test的类:moduleTopmoduleFooclassSomeTest但是,如果我尝试通过使用::指定模块来最小化缩进:moduleTop::FooclassFailure这失败了:NameError:uninitializedconstantTop::Foo::Test这是一个错误,还是仅仅是Ruby解析变量名的方式的逻辑结果? 最佳答案 Isthisabug,or

  5. ruby - 如何验证 IO.copy_stream 是否成功 - 2

    这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下

  6. Ruby 文件 IO 定界符? - 2

    我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的

  7. ruby - inverse_of 是否适用于 has_many? - 2

    当我使用has_one时,它​​工作得很好,但在has_many上却不行。在这里您可以看到object_id不同,因为它运行了另一个SQL来再次获取它。ruby-1.9.2-p290:001>e=Employee.create(name:'rafael',active:false)ruby-1.9.2-p290:002>b=Badge.create(number:1,employee:e)ruby-1.9.2-p290:003>a=Address.create(street:"123MarketSt",city:"SanDiego",employee:e)ruby-1.9.2-p290

  8. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting - 2

    1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里

  9. ruby - "undefined method"用于 rails 模型 - 2

    我正在使用带有Rails的Devise,我想添加一个方法“getAllComments”,所以我这样写:classUser在我的Controller中:defdashboard@user=current_user@comments=@user.getAllComments();end当我访问我的url时,我得到了undefinedmethod`getAllComments'for#我做错了什么?谢谢 最佳答案 因为getAllComments是一个类方法,而您正试图将其作为实例方法访问。您要么需要访问它:User.getAllCom

  10. ruby - 为什么不能使用类IO的实例方法noecho? - 2

    print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上

随机推荐