HurkNburkS
HurkNburkS

Reputation: 5510

dismissViewControllerAnimated not being called on iPhone

I have the following code where I am trying to show a PDF preview. It words perfectly on an iPad however when I am trying to do it on a iPhone it dosnt work.

QLPreviewController* preview = [[QLPreviewController alloc] init];
        preview.dataSource = self;
        [self dismissViewControllerAnimated:YES completion:^{
            [self presentViewController:preview animated:YES completion:nil];
        }];

The thread on the iPhone never makes it to this line

[self presentViewController:preview animated:YES completion:nil];

but works fine on ipad.. I am not sure what to even look at. Any help would be appreaciated.

Upvotes: 1

Views: 182

Answers (2)

DV_
DV_

Reputation: 346

Try to use

[self.presentingViewController presentViewController:preview animated:YES completion:nil];

instead of

[self presentViewController:preview animated:YES completion:nil];

Upvotes: 1

Adeel Miraj
Adeel Miraj

Reputation: 2496

To access the instances/variables (that are declared outside of the block) inside a block, you need to declare those instances/variables like this: __block type identifier = initial value (optional) e.g, in your case use __block QLPreviewController* preview = [[QLPreviewController alloc] init];

Upvotes: 1

Related Questions