shaheen
shaheen

Reputation: 411

UINavigationController not popping view on back button

I have a UINavigationController. I've got a UIViewController that I've pushed onto the stack using pushViewController. The previous view controller has a backBarButtonItem simply titled "Cancel."

While the new view animates in correctly, when I tap Cancel, the navigation bar animates as if the view was popped, but the new view doesn't go away. Do I need to implement a delegate somewhere?

Upvotes: 0

Views: 1350

Answers (1)

Mohammad Abdurraafay
Mohammad Abdurraafay

Reputation: 1072

Try this,

First Create a UIButton then Create one UIBarButtonItem with Custom view, considering UIButton as custom view for UIBarButtonItem.

Consider button to target event for popping view controller.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 35, 35);
[button setImage:[UIImage imageNamed:@"dots.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(backBarButton:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:button];

self.navigationItem.leftBarButtonItem = backBarButton;

- (void)backBarButton:(id)sender {
NSLog(@"%s", __FUNCTION__);
self.navigationController.navigationBarHidden = YES;
[self.navigationController popViewControllerAnimated:YES];
}

Upvotes: 1

Related Questions