代码之家  ›  专栏  ›  技术社区  ›  Steve Weller

有没有比这更好的办法来隐藏背后的巴布托主义?

  •  9
  • Steve Weller  · 技术社区  · 17 年前

    我有一种隐藏导航控制器使用的后退按钮的方法。它是由前一个控制器设置的,而不是管理当前视图的控制器,因此很难访问它。我需要在编辑模式下这样做,这样才能防止用户离开屏幕。

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

    有更好的方法吗?

    3 回复  |  直到 17 年前
        1
  •  45
  •   Raj    17 年前

    使用此按钮可隐藏“后退”按钮

    [self.navigationItem setHidesBackButton:YES]
    

    [self.navigationItem setHidesBackButton:NO]
    
        2
  •  1
  •   nevan king    14 年前

    以下是我在视图控制器中使用的方法,用于在启用和禁用编辑时显示和隐藏“后退”按钮:

    - (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];
    }
    
        3
  •  1
  •   Mohsen Fard    6 年前

    self.navigationItem.setHidesBackButton(true, animated: false)
    
        4
  •  0
  •   goolee    13 年前

    使用从情节提要到视图控制器的条形按钮的“强”(默认情况下不是“弱”)创建一个插座。 其目的是在将左/右栏按钮设置为nil时不会松开参考。