繁体   English   中英

如何将UIBarButtonItem添加到QLPreviewController

[英]How to add UIBarButtonItem to QLPreviewController

我已经读过这个问题QLPreviewController删除或添加UIBarButtonItems,但这不是我想要的。 我想保留导航栏中的“打印”按钮 ,但还要在导航栏中添加新的“删除文档”按钮。

我尝试了这个:

QLPreviewController *previewer = [[[QLPreviewController alloc] init] autorelease];
[previewer setDataSource:self];

UIBarButtonItem *saveButton = [[UIBarButtonItem alloc]initWithTitle:@"Salva Documento" style:UIBarButtonItemStyleBordered target:self action:@selector(saveFileToDocuments)];
NSArray *buttons = [NSArray arrayWithObjects:[[previewer navigationItem]rightBarButtonItem],saveButton, nil];
[[previewer navigationItem]setRightBarButtonItems:buttons];

但这没有用。

    UIBarButtonItem *rbb;
-(void)addRightButton{
    if (!rbb) {
        UIButton *orderButton = [UIButton buttonWithType:UIButtonTypeCustom];
        orderButton.frame = CGRectZero;
        rbb = [[UIBarButtonItem alloc] initWithCustomView:orderButton];
    }

    self.navigationItem.rightBarButtonItem = rbb;
}

- (void)viewDidLoad{
    [super viewDidLoad];
    [self performSelector:@selector(addRightButton) withObject:nil afterDelay:0.2];
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self addRightButton];

}

因为您说“ 4.x没问题”,所以您有问题。

UINavigationItem [setRightBarButtonItems: animated:]文档(为您提供链接的文档)说,此功能仅在iOS 5.0及更高版本上有效。

在iOS 4.0上将无法使用。

另外,您应该在该setRightBarButtonItems:调用中添加一个animated:参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM