views:

85

answers:

1

Hi friends,
I am new at Objective C. I am just trying to build an iphone app. I have created some NIB file, and i have gone to other NIB file by creating an object and using this code:

scoreViewController *sviewController = [[scoreViewController alloc] initWithNibName:@"scoreViewController" bundle:nil];
    self.scoreView = sviewController;
    [sviewController release];
    // Setup the animation
    [self.navigationController pushViewController:self.scoreView animated:YES];

Now I want to come back to the same page. For this case I have done the same work, but it does not work when I add the previous page header file name.

mainViewController *mainviewController = [[mainViewController alloc] initWithNibName:@"mainViewController" bundle:nil];
    self.mcoreView = mainviewController;
    [mainviewController release];
    // Setup the animation
    [self.navigationController pushViewController:self.mcoreView animated:YES];

So, I will be most grateful if you were so nice to post your comment.

+2  A: 

I am not 100% sure what you are asking, but I think you want to go back from the the second controller to the first. What you are doing here is instantiating a second instance of the first controller (so you now have 3 controllers), and pushing it onto the stack. Assuming I have this correct, then if you want to move back to the first controller you should be popping the second controller off the stack, not adding a 3rd:

//mainViewController *mainviewController = [[mainViewController alloc] initWithNibName:@"mainViewController" bundle:nil];
//self.mcoreView = mainviewController;
//[mainviewController release];

// Setup the animation
[self.navigationController popViewControllerAnimated:YES];
Louis Gerbarg
Thank, friend. It has done the work.