UINavigationController not popping view on back button

强颜欢笑 提交于 2019-12-24 21:59:33

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/4301993/uinavigationcontroller-not-popping-view-on-back-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!