“[setToolBarHidden:YES]”不工作
我有一个 UINavigationController,在它的视图控制器之一中,我使工具栏不隐藏在 viewDidAppear 中。效果很好。但是,在 viewDidDisappear 中,我将其设置为隐藏,但它并没有隐藏。我做错了什么?这是相关代码:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[self navigationController] setToolbarHidden:NO];
UIBarButtonItem *buttomSubmit = [[UIBarButtonItem alloc] initWithTitle:@"Submit"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done)];
UIBarButtonItem *buttonPrint = [[UIBarButtonItem alloc] initWithTitle:@"Print"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done)];
UIBarButtonItem *buttonUnits = [[UIBarButtonItem alloc] initWithTitle:@"Units"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done)];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
[self setToolbarItems:[NSArray arrayWithObjects:buttonUnits, flexSpace, buttomSubmit, buttonPrint, nil]];
[buttomSubmit release];
[buttonPrint release];
[buttonUnits release];
[flexSpace release];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[self navigationController] setToolbarHidden:YES];
}
谢谢!
I have a UINavigationController and in one of it's view controller, I am making the toolbar not hidden in viewDidAppear. Works just fine. But, in viewDidDisappear, I am setting it as hidden but it does not get hidden. What am I doing wrong? Here's the relevant code:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[self navigationController] setToolbarHidden:NO];
UIBarButtonItem *buttomSubmit = [[UIBarButtonItem alloc] initWithTitle:@"Submit"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done)];
UIBarButtonItem *buttonPrint = [[UIBarButtonItem alloc] initWithTitle:@"Print"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done)];
UIBarButtonItem *buttonUnits = [[UIBarButtonItem alloc] initWithTitle:@"Units"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(done)];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
[self setToolbarItems:[NSArray arrayWithObjects:buttonUnits, flexSpace, buttomSubmit, buttonPrint, nil]];
[buttomSubmit release];
[buttonPrint release];
[buttonUnits release];
[flexSpace release];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[[self navigationController] setToolbarHidden:YES];
}
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
viewDidDisappear
在视图离开屏幕后调用。如果视图由于按下后退按钮而离开屏幕,它将被从导航控制器堆栈中弹出。来自 UIViewController 类参考 注释在 navigationController 属性上:
这意味着
[self navigationController]
返回 nil,因此setToolbarHidden
消息被发送到 nil 并且不起作用。要在新视图加载后隐藏它(这似乎是您想要的),您可以在新视图控制器的 viewDidAppear 方法中进行隐藏。
viewDidDisappear
is called after the view has gone off screen. If the view has gone off screen because of pressing the back button it will have been popped off the navigation controller stack.From the UIViewController class reference notes on the navigationController property:
This means that
[self navigationController]
is returning nil and therefore thesetToolbarHidden
message is sent to nil and has no effect.To hide it after the new view loads which is what you seem to want you could do the hiding in the
viewDidAppear
method of the new view's controller instead.在视图离开屏幕之前隐藏它是可以的。
It's okay to hide it before the view goes off screen.