还有比这里更好的隐藏backBarButtonItem的方法吗?

问题描述 投票:9回答:4

我有一种隐藏导航控制器使用的后退按钮的方法。它是由前一个控制器设置的,而不是由管理当前视图的控制器设置的,因此很难到达。我需要在编辑模式下执行此操作,以便可以防止用户离开屏幕。

if(self.editing) {
    // Get rid of the back button   
    UIView *emptyView = [[UIView alloc] init];;
    UIBarButtonItem *emptyButton = [[[UIBarButtonItem alloc] initWithCustomView:emptyView] autorelease];
    [self.navigationItem setLeftBarButtonItem:emptyButton animated:YES];
} else {
    // Restore the back button
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];        
}

有更好的方法吗?

iphone uinavigationbar
4个回答
45
投票

使用此按钮隐藏后退按钮

[self.navigationItem setHidesBackButton:YES]

使用此按钮显示后退按钮

[self.navigationItem setHidesBackButton:NO]

1
投票

这是启用和禁用编辑后在视图控制器中用于显示和隐藏后退按钮的方法:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    if (editing) {
        // Disable the back button
        [self.navigationItem setHidesBackButton:YES animated:YES];
    }
    else {
        // Enable the back button
        [self.navigationItem setHidesBackButton:NO animated:YES];
    }

    [super setEditing:editing animated:animated];
}

0
投票

从情节提要到视图控制器,使条形按钮的坚固(默认不弱)的插座。目的不是在将左/右工具栏按钮设置为零时放松参考。


0
投票

Swift5:

self.navigationItem.setHidesBackButton(true, animated: false)
© www.soinside.com 2019 - 2024. All rights reserved.