目标我想隐藏我的导航栏但我想显示navigationItem的rightBarButtonItem

时间:2015-08-06 12:19:16

标签: ios objective-c iphone uinavigationitem

我是Objective-c的新手。我正在尝试隐藏导航栏我使用此代码并且它的工作完美但问题是当我无法显示navigationItem的右边的BarButtonItem时隐藏导航栏/ p>

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    self.navigationController.navigationBarHidden = YES;
   // self.navigationItem.rightBarButtonItem.enabled = NO;

}

我将此代码用于navigationItem

-(void)loadBackButton{
     /*UIBarButtonSystemItemDone */
     buttonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(dismiss:)];
     self.navigationItem.rightBarButtonItem = buttonItem;

}

- (void)dismiss:(id)sender {
    NSLog(@"Dismis Done");
    [self dismissModalViewControllerAnimated:YES];
    //[self.view removeFromSuperview];
}

我的- (void)viewDidLoad吼叫

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
     //for load navigationItem's 
    [self loadBackButton];
    self.navigationItem.rightBarButtonItem.enabled = YES;

    // Do any additional setup after loading the view from its nib.
}

1 个答案:

答案 0 :(得分:2)

隐藏NavigationBar也会隐藏您的rightBarButtonItem。其中一个可能的解决方案是使导航栏透明。您可以使用以下代码执行此操作:

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.view.backgroundColor = [UIColor clearColor];