iphoneobjective-ciosviewdidloadrightbarbuttonitem

"self.navigationItem.rightBarButtonItem" Not working


I have the following code taken straight from the NavBar sample code from Apple. I put this in the viewDidLoad method for a view in my app that is being presented modally, and it wont work.

UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"AddTitle", @"")
                                                               style:UIBarButtonItemStyleBordered
                                                              target:self
                                                              action:@selector(addAction:)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;

Any Suggestions?


Solution

  • You need to use these lines of code on the page where you present the other view.

    sceondController *obj=[[[sceondController alloc] initWithNibName:@"sceondController" bundle:nil] autorelease];
            UINavigationController *navController=[[[UINavigationController alloc] initWithRootViewController:obj] autorelease];
    
            [self.navigationController presentModalViewController:navController animated:NO];
    

    and in second view use same code which you are using for making navigation button.

    May be it resolves your problem.