Skip to content

Instantly share code, notes, and snippets.

@0xced
Created September 20, 2012 18:04
Show Gist options
  • Select an option

  • Save 0xced/3757421 to your computer and use it in GitHub Desktop.

Select an option

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
#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