Created
September 20, 2012 18:04
-
-
Save 0xced/3757421 to your computer and use it in GitHub Desktop.
Workaround a bug in UIKit that prevents QLPreviewController to be loaded from a nib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <QuickLook/QuickLook.h> | |
| #import <objc/runtime.h> | |
| @implementation QLPreviewController (NSCodingFix) | |
| + (void) load | |
| { | |
| Method initWithCoder = class_getInstanceMethod(self, @selector(initWithCoder_nscodingfix:)); | |
| class_addMethod(self, @selector(initWithCoder:), method_getImplementation(initWithCoder), method_getTypeEncoding(initWithCoder)); | |
| } | |
| - (id) initWithCoder_nscodingfix:(NSCoder *)decoder | |
| { | |
| if (!(self = [super initWithCoder:decoder])) | |
| return nil; | |
| @try | |
| { | |
| #pragma clang diagnostic push | |
| #pragma clang diagnostic ignored "-Warc-performSelector-leaks" | |
| [self performSelector:NSSelectorFromString([@[@"_", @"common", @"Init"] componentsJoinedByString:@""])]; | |
| #pragma clang diagnostic pop | |
| } | |
| @catch (NSException *exception) | |
| { | |
| NSLog(@"-[QLPreviewController _commonInit] failed, trouble ahead."); | |
| } | |
| return self; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment