bov*_*llo 11 objective-c qlpreviewcontroller ios6
我的目标是在iOS6的iPad应用程序中使用QLPreviewController,使用顶部工具栏中的自定义操作项按钮.我有解决方案,直到iOS5.1.我使用了一个扩展QLPreviewController的类,在组件生命周期中我做了类似的事情
[[self navigationItem] setRightBarButtonItems:[NSArray arrayWithObject:[self buildCustomButton]]];
Run Code Online (Sandbox Code Playgroud)
使用iOS6这个技巧不起作用,现在似乎不可能改变navigationItem配置.我认为可能涉及到UIActivity和Social Framework的引入,也许在navigationItem上工作并不是更有效,但我可以找到任何解决方案.有什么建议吗?谢谢再见
我真的需要一个解决方案,所以我做了这个.
是的,这很难看.是的,它可能会在任何时候破裂.是的,我会陷入困境,但我的老板却生气地闭着眼睛盯着我......现在.
@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
Run Code Online (Sandbox Code Playgroud)
史蒂夫乔布斯将在我的梦中追捕我,直到找到合适的解决方案......
我尝试了很长时间来更换这个按钮。查看子视图等。看起来这个操作/共享按钮被作为导航层放置。酒吧。我最终通过在 QLPreviewController 子类中添加一个按钮而不是标题来为自己解决这个问题。
- (void)viewDidLoad
{
[super viewDidLoad];
// Button in center of Navigation Bar
UISegmentedControl *button = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:LS(@"Save"), nil]];
button.frame = CGRectMake(0, 0, 100, 30);
button.center = self.view.center;
button.momentary = YES;
button.segmentedControlStyle = UISegmentedControlStyleBar;
button.tintColor = [UIColor colorWithHue:0.6 saturation:0.33 brightness:0.69 alpha:0];
[button addTarget:self action:@selector(saveToDocumentsClicked) forControlEvents:UIControlEventValueChanged];
self.navigationItem.titleView = button;
}
Run Code Online (Sandbox Code Playgroud)