Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationController: How to manage Cancel button and back button

Lets say I have two controller A & B... When I'll navigate from A to B then back button on B Controller will be A.

So my problem is... On a button click I have to change backButton to Cancel Button.. and on another back button it should appear backButton A in back button arrow style.

Please suggest.

like image 765
Tariq Avatar asked Aug 18 '11 09:08

Tariq


1 Answers

Do the following,

To SHOW the Cancel button:

- (void)showCancelButton {

    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(someMethod)];
    [self navigationItem] setLeftBarButtonItem:cancelButton];
    [cancelButton release];
}

To HIDE the Cancel button:

- (void)hideCancelButton {

    [self navigationItem] setLeftBarButtonItem:nil];
}

Make sure self.navigationController.navigationItem.hidesBackButton is NO.

like image 138
EmptyStack Avatar answered Sep 30 '22 12:09

EmptyStack