문제

I already read this question QLPreviewController remove or add UIBarButtonItems but it's not what I'm looking for. I would like to keep the "Print" button in the navigation Bar but also add a new "Delete Document" button in the navigation bar.

I tried this:

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];

But it didn't work.

도움이 되었습니까?

해결책

Because you said "4.x will be fine", there's your problem.

The documentation for UINavigationItem [setRightBarButtonItems: animated:] (documentatin linked there for you) say that this function only works on iOS 5.0 and newer.

It will not work on iOS 4.0.

Also, you should add an animated: parameter to that setRightBarButtonItems: call.

다른 팁

    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];

}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top