Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quicklook/QLPreviewController delegate methods are not calling in iOS 10 Xcode 8

Currently I am testing my current version in iOS10. I am using Xcode 8 beta 6 for testing. Here Quicklook/QLPreviewController delegate methods are not calling. This code set had been worked with XCode 7 and iOS 9.3 versions. I checked this issue in Apple Developer forum. But could not find a answer. Anyone have fixed this issue? (I am using Objective-C)

How to use Quicklook/QLPreviewController in XCode 8 (iOS 10)?

//----------------- SOLUTION for iOS 10 ( previewer as a subview) -------------------

This issue is occurred when you add the the previewer as a subview. Then we are using below code lines mainly in iOS 9.3 and below versions.

[self addChildViewController:previewer];
self.view addSubview:previewer.view];
[previewer didMoveToParentViewController:self];

In iOS 10 issue comes due to the below code line.

[self addChildViewController:previewer];

For iOS 10 we need to check the version and add above code line. Below is the working code set.

    QLPreviewController* previewer = [[QLPreviewController alloc] init];

    previewer.dataSource = self;
    previewer.delegate = self;
    // To avoid iOS 10 previewer issue.
    if (SYSTEM_VERSION_LESS_THAN(@"10.0")) {
        [self addChildViewController:previewer];
    }
    CGFloat width = self.view.frame.size.width;
    CGFloat height = self.view.frame.size.height;
    previewer.view.frame = CGRectMake(0, 102, width, height-300);
    [self.view addSubview:previewer.view];

    [previewer didMoveToParentViewController:self];
like image 467
Null Value Exception Avatar asked Aug 31 '16 01:08

Null Value Exception


1 Answers

I met this problem too, but I can't fix this issue by your solution.. Here is my code:

QLPreviewController *preview = [[QLPreviewController alloc] init];
[preview setDataSource:self];
[preview setDelegate:self];

if(SYSTEM_VERSION_LESS_THAN(@"10.0"))
{
    [self addChildViewController:preview];
}

[preview didMoveToParentViewController:self];
[self.view addSubview:preview.view]; 
like image 104
Wilson Lai Avatar answered Nov 02 '22 17:11

Wilson Lai