开发者

Uinavigationitem back button not visible until i click on the left side of nav. bar

I have 3 view controllers (VCs) A B C. Firstly i present A. Then i push B and then i push C. After i push C, i remove B from the stack so user would go back to A if he pressed back button. I use this code for pushing C and removing B:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Nazaj" style:UIBarButtonItemStylePlain target:nil action:nil]; 

    //we push C
    PorabaControllerR *anotherViewController = [[PorabaControllerR alloc] initWithNibName:@"PorabaViewR" bundle:nil];
    //[anotherViewController setTitle:@"Pregled porabe"];
    [anotherViewController.navigationItem setBackBarButtonItem:backButton];
    [self.navigationController pushViewController:anotherViewController animated:YES];
    [anotherViewController release];

    //we remove B from the s开发者_StackOverflow社区tack
    NSMutableArray *allControllers = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];

    [allControllers removeObjectAtIndex:[allControllers count] - 2];
    //[allControllers objectAtIndex:[allControllers count] - 2]
    [self.navigationController setViewControllers:allControllers animated:NO];
    [allControllers release];

The problem is that uinav. item's back button doesn't show on C until i go above it and click it. (on B is OK). Is there any good way how to debug it or watch back button title change during execution? Any other idea?

EDIT: I tried using Vijay's idea:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Nazaj" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonClick:)];

-(IBAction)leftBarButtonClick:(UIButton *) sender {

NSLog(@"clicked left"); 
//back to home screen
[self.navigationController popToRootViewControllerAnimated:YES];

}

but this function is not called at all and back button is still hidden until i go over it and click it.


simply use this code in ur backbarbutton or leftbarbutton action.

inside ur function

[self.navigationController popToRootViewControllerAnimated:YES];

OR

[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:0] animated:YES];


I solved it with this code:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Nazaj" style:UIBarButtonItemStylePlain target:nil action:nil]; 

    PorabaControllerR *anotherViewController = [[PorabaControllerR alloc] initWithNibName:@"PorabaViewR" bundle:nil];
    [anotherViewController.navigationItem setBackBarButtonItem:backButton];

    NSMutableArray *allControllers = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];

    [allControllers removeObjectAtIndex:1]; //we remove B
    [allControllers insertObject:anotherViewController atIndex:1]; //we push C
    [self.navigationController setViewControllers:allControllers animated:YES];
    [allControllers release];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜