简体   繁体   English

NavigationController的backButton不出现

[英]backButton of NavigationController don't appear

I have already post this question but this time I post code. 我已经发布了这个问题,但是这次我发布了代码。 So I have a uiviewController, and in the viewDidLoad of this viewController I hide the backButton of the navigationController. 所以我有一个uiviewController,在这个viewController的viewDidLoad中,我隐藏了navigationController的backButton。 After that, I push a new uiviewcontroller, and I set the backbutton to visible in the viewDidLoad, but the backbutton is still hidden... 之后,我按下一个新的uiviewcontroller,然后将backbutton在viewDidLoad中设置为可见,但是backbutton仍然是隐藏的...

Implementation of the first uiviewcontroller 第一个uiviewcontroller的实现

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"page2page2page2page2page2";

    self.navigationItem.hidesBackButton = TRUE;
}

-(IBAction)click
{
    page3 *controller = [[page3 alloc] init];

    [self.navigationController pushViewController:controller animated:YES];

    [page3 release];
}

Implementation of the page 3 执行第3页

- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title = @"page3";
    self.navigationItem.hidesBackButton = FALSE;

}

and the page3 has no backbutton, but the space is created for the button, because the tile "page 3" is on the right and not in the center... all this happen with the ios 4.2 并且page3没有后退按钮,但是为按钮创建了空间,因为图块“ page 3”在右侧而不是在中心...这一切都发生在ios 4.2中

thx 谢谢

My trick is setting setNavigationBarHidden to YES and immediately NO. 我的技巧是将setNavigationBarHidden设置为YES,然后立即设置为NO。

[self.navigationItem setHidesBackButton:NO animated:YES];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController setNavigationBarHidden:NO];

So as this the backButton not be animated but it's really work and my manager have not notice it ;P 因此,backButton并未设置动画,但它确实有效,我的经理没有注意到它; P

Neither of the above workarounds seemed to work for me. 以上两种变通办法似乎都不适合我。 However when the third view was being displayed, i could see the button blink for a moment. 但是,当显示第三个视图时,我可以看到按钮闪烁了片刻。 So I suspected the problem (bug) has to do with the animation 所以我怀疑问题(错误)与动画有关

When change animated to NO on the pushViewController the problem went away 当在pushViewController上将动画更改为NO时,问题消失了

- (IBAction)btnNext:(id)sender {

    [[self navigationController] pushViewController:thirdViewController animated:NO];
}

I get the same behaviour and I must say I find it quite strange. 我有相同的行为,我必须说我觉得这很奇怪。 I can't say why it doesn't work but as a workaround you can do: 我不能说为什么它不起作用,但是作为一种解决方法,您可以执行以下操作:

In page2: 在第2页中:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.navigationItem setHidesBackButton:YES animated:YES];
} 

And in page3: 在第3页中:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self.navigationItem setHidesBackButton:NO animated:YES];
}

And remove the calls to self.navigationItem.hidesBackButton = ... in both controllers. 并删除两个控制器中对self.navigationItem.hidesBackButton = ...的调用。

Well, I had the same problem running iOS 4.2. 好吧,我在运行iOS 4.2时遇到了同样的问题。 The back button would refuse to appear. 后退按钮将拒绝出现。 Upon autoroating to landscape, it then appears. 旋转到风景后,它就会出现。 My solution was to do the following - This fixed the problem...or should we say its a workaround ;) 我的解决方案是执行以下操作-这解决了问题...或者应该说这是一种解决方法;)

- (void)viewDidLoad 
{
    [super viewDidLoad];
    self.navigationItem.hidesBackButton = YES;
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    self.navigationItem.hidesBackButton = NO;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM