【问题标题】:UINavigationController not popping view on back buttonUINavigationController 没有在后退按钮上弹出视图
【发布时间】:2010-11-29 08:30:13
【问题描述】:

我有一个 UINavigationController。我有一个 UIViewController,我使用 pushViewController 将其推入堆栈。前一个视图控制器有一个简单的名为“取消”的 backBarButtonItem。

虽然新视图的动画效果正确,但当我点击取消时,导航栏的动画效果就像视图被弹出一样,但新视图并没有消失。我需要在某处实现委托吗?

【问题讨论】:

    标签: ios uinavigationcontroller


    【解决方案1】:

    试试这个,

    首先创建一个UIButton,然后使用自定义视图创建一个UIBarButtonItem,将UIButton 视为UIBarButtonItem 的自定义视图。

    考虑将按钮作为弹出视图控制器的目标事件。

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

    【讨论】:

    • 我认为这可能是一个更简单的答案。只需添加 [self.navigationController popViewControllerAnimated:YES];调用按钮单击事件将解决问题。
    猜你喜欢
    • 2012-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 2010-12-23
    • 2011-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多