Tariq
Tariq

Reputation: 9979

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.

Upvotes: 5

Views: 5358

Answers (1)

EmptyStack
EmptyStack

Reputation: 51374

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.

Upvotes: 10

Related Questions