【问题标题】:Navigation Bar logic implementation导航栏逻辑实现
【发布时间】:2013-07-30 07:03:16
【问题描述】:

我已经从控件中获取导航栏并添加了一个右栏按钮,它也是从控件中获取的我的要求是我只想在视图出现时隐藏右栏按钮,并且我已经为右栏按钮编写了下拉操作。我在这个视图控制器中有一个称为列表视图控制器的额外视图控制器当我选择一个对象时我有 3 个对象然后将其推送到主视图控制器并且右栏按钮可见并且当我单击右栏按钮时选择对象将被添加到下拉列表中,任何人都可以帮助我。

[self loadMenu];
[self btn];


self. navigationItem.title = @"sample";
[super viewDidLoad];


appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

【问题讨论】:

    标签: iphone uinavigationbar uibarbuttonitem


    【解决方案1】:

    我对你的要求有点困惑,但我相信你应该做的就是

    self.navigationController.navigationItem.rightBarButtonItem.enabled = NO;
    

    这将隐藏按钮,因为它设置为未启用集....

    所以,要从一个视图转到另一个视图,只需这样做

    [navController pushViewController:viewController animatedYES];
    

    然后从那个视图向后退

    [navController popViewControllerAnimated:YES];
    

    现在完全添加它:

     // creating UIViewController objects for reference later 
     View1 *view1 = [[View1 alloc] init];
     View2 *view2 = [[View2 alloc] init];
    
     // you are setting the view1 right navigation button in the view1 viewDidLoad
     self.navigationController.navigationItem.rightBarButtonItem.enabled = NO;
    
     // now you are pushing to second view
     [navController pushViewController:view2 animated:YES];
    
     // now, in the view2 class, where you get the image that sends the 
     // user back to view 1, just do
     [view2.navController popViewControllerAnimated:YES];
    
     // and then wherever you do the pop as shown above, you need to set the
     // view1 right bar button to enabled
     view1.navigationController.navigationItem.rightBarButtonItem.enabled = YES;
    

    希望这会有所帮助!

    【讨论】:

    • 感谢您的回复,实际上我有 2 个视图控件,例如 viewcontrol1 和 2。在视图控件一中,当我启动我的应用程序时,我有一个右键按钮,我应该隐藏右栏按钮。第二件事是在视图 control2 中,当我选择一个要推送到视图 controller1 的图像时,我在列表中有三个对象(像图像一样的行中的项目),并且应该启用右栏按钮
    • 不客气,但你想做的是当你推送视图时,你使用 [self.navigationController pushViewController:(UIViewController) animated:YES];当您想返回时,只需执行 popViewController
    • self.navigationController.navigationItem.rightBarButtonItem.enabled = NO;我应用这个但不工作
    • 再次感谢您,我为推送和弹出它写得很好,但问题是当我启动我的应用程序 barbutton 项目时应该隐藏并在 viewcontroller2 中,当我在视图控制器 1 barbutton 项目中选择行时可见
    • 将 self.navigationController 更改为您的 navigationController 变量名称..
    猜你喜欢
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多