UINavigationController 不会在后退按钮上弹出视图 [英] UINavigationController not popping view on back button

查看:31
本文介绍了UINavigationController 不会在后退按钮上弹出视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UINavigationController.我有一个 UIViewController,我使用 pushViewController 将它推送到堆栈上.前面的视图控制器有一个简单的标题为取消"的 backBarButtonItem.

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?

推荐答案

试试这个,

首先创建一个 UIButton 然后创建一个带有自定义视图的 UIBarButtonItem,考虑将 UIButton 作为 UIBarButtonItem 的自定义视图.

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

这篇关于UINavigationController 不会在后退按钮上弹出视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆