Domanda

Ho già letto questa domanda QlPreviewController Rimuovi o aggiungi UiBarButtonItems Ma non è quello che sto cercando. Vorrei Mantieni il pulsante "Stampa" nella barra di navigazione ma Aggiungi anche Un nuovo pulsante "Elimina documento" nella barra di navigazione.

Ho provato questo:

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

Ma non ha funzionato.

È stato utile?

Soluzione

Perché hai detto "4.x andrà bene", c'è il tuo problema.

La documentazione per UINavigationItem [setRightBarButtonItems: animated:] (Documentatin collegata lì per te) Say che questa funzione funziona solo su iOS 5.0 e più recente.

Lo farà non Lavora su iOS 4.0.

Inoltre, dovresti aggiungere un animated: parametro a quello setRightBarButtonItems: chiamata.

Altri suggerimenti

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

}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top