在iOS6中使用QLPreviewController自定义navigationItem按钮 [英] Custom navigationItem button with QLPreviewController in iOS6

查看:105
本文介绍了在iOS6中使用QLPreviewController自定义navigationItem按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是在iOS6的iPad应用程序中使用QLPreviewController,使用顶部工具栏中的自定义操作项按钮。
我有解决方案,直到iOS5.1。我使用了一个扩展QLPreviewController的类,在组件生命周期中我做了类似的事情。

my goal is to use QLPreviewController in my iPad application for iOS6, using my custom Action item button in the top toolbar. I had solution until iOS5.1. I used a class that extends QLPreviewController and during component lifecycle I did something like

[[self navigationItem] setRightBarButtonItems:[NSArray arrayWithObject:[self buildCustomButton]]];

使用iOS6这个技巧不起作用,现在似乎无法改变navigationItem配置。我认为可能涉及UIActivity和社交框架的介绍,也许在navigationItem上工作并不是更有效,但我可以找到任何解决方案。
有什么建议吗?
谢谢,再见

With iOS6 this trick doesn't work more, and now it seems impossible change navigationItem configuration. I think that introduction of UIActivity and Social Framework could be involved and maybe it's no more effective to work on navigationItem, but I can find any solution. Any suggestion? Thanks, bye

推荐答案

我真的需要一个解决方案,所以我做了这个。

I really really needed a solution, so I made this up.

是的,这很难看。是的,它可能随时都会破裂。是的,我会陷入困境,但是我的老板确实停下来,愤怒地盯着我......现在。

Yes, it's ugly. Yes, it may break at any time. And yes, I'll go strait to dev hell, but my boss did stop stare at me with angry eyes...for now.

@implementation UINavigationItem (Custom)

void MethodSwizzle(Class c, SEL origSEL, SEL overrideSEL);

- (void) override_setRightBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated{   
    if (item && [item.target isKindOfClass:[QLPreviewController class]] && item.action == @selector(actionButtonTapped:)){
        QLPreviewController* qlpc = (QLPreviewController*)item.target;
        [self override_setRightBarButtonItem:qlpc.navigationItem.rightBarButtonItem animated: animated];
    }else{
        [self override_setRightBarButtonItem:item animated: animated];
    }
}

+ (void)load {
    MethodSwizzle(self, @selector(setRightBarButtonItem:animated:), @selector(override_setRightBarButtonItem:animated:));
}

void MethodSwizzle(Class c, SEL origSEL, SEL overrideSEL) {
    Method origMethod = class_getInstanceMethod(c, origSEL);
    Method overrideMethod = class_getInstanceMethod(c, overrideSEL);

    if (class_addMethod(c, origSEL, method_getImplementation(overrideMethod), method_getTypeEncoding(overrideMethod))) {
        class_replaceMethod(c, overrideSEL, method_getImplementation(origMethod), method_getTypeEncoding(origMethod));
    }else{
        method_exchangeImplementations(origMethod, overrideMethod);
    }
}

@end

Steve乔布斯会在我的梦中追捕我,直到我找到一个合适的解决方案......

Steve Jobs will hunt me in my dreams until I find a proper solution...

这篇关于在iOS6中使用QLPreviewController自定义navigationItem按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆