Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello,

I am working on a project using storyboards. The initial scene is a UITableViewController embedded in a Navigation Controller. When a button is pressed on this scene, it segues to a UIViewController that is embedded in another Navigation Controller. Upon the ViewController loading, a UIAlertView appears with a cancel button. This button is handled by my view controller. When is it pressed it should segue back to the TableView controller.

Code:
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
        NSLog(@"Canceled.");
        [self.navigationController popViewControllerAnimated:YES];
        NSLog(@"The number of view controllers: %i", [[self.navigationController viewControllers] count]);
    }else{
            
    }
}

The NSLog fires as expected letting me know that the cancel button has been pressed. Then the popViewControllerAnimated: does nothing. According to the documentation it should set the previous view controller as the current one (in this case the TableViewController). When I log the number of view controllers in the stack, the value is 1.

Is this because the TableViewController is being handled by a separate Navigation Controller?

And if so, what is the best way to unwind the segue? Or, am I completely botching something?

Could someone please help me understand my mistake(s)?

Thanks!
 
Last edited:
You are popping one UINavigationController expecting it to have an effect on another UINavigationController.

Is there a particular reason you're using two separate UINavigationControllers?
 
You are popping one UINavigationController expecting it to have an effect on another UINavigationController.

I suspected that was the case.

Is there a particular reason you're using two separate UINavigationControllers?

I am using two separate UINavigationControllers as Apple's Storyboards tutorial I read recently embedded each ViewController with a separate UINavigationController.

This is my first time using storyboards as I am usually working on OS X programs where Storyboards are not an option.

I know if I wasn't doing this through a UIAlertView I could connect a button in Interface Builder to exit: , but as far as I know, UIAlertView buttons can't be connected in IB.


Is there a way I can still go backwards if I am using two navigation controllers?

Thanks
 
Last edited:
I am using two separate UINavigationControllers as Apple's Storyboards tutorial I read recently embedded each ViewController with a separate UINavigationController.

Which tutorial is this? Please be as specific as possible. That is, please provide a URL, at least. Thanks.
 
Does the segue to the second view present it modally or push it onto the navigation stack? Because you'll want to reverse this in your button action, either using dismissViewControllerAnimated:completion: or popViewControllerAnimated:
 
Does the segue to the second view present it modally or push it onto the navigation stack? Because you'll want to reverse this in your button action, either using dismissViewControllerAnimated:completion: or popViewControllerAnimated:

It is presented modally. The methods you suggested do not work. I don't know why though. I suspect it is because my two view controllers are handled by two different navigation controllers. How should I move backwards with that being the case?

Thanks.
 
Last edited:
It is presented modally. The methods you suggested do not work. I don't know why though. I suspect it is because my two view controllers are handled by two different navigation controllers. How should I move backwards with that being the case?

Thanks.

Can you show me the code you used in your alertView:clickedButtonAtIndex: that calls dismissViewControllerAnimated:completion:?

I tried the following and it works fine for me:
Code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        NSLog(@"Canceled.");
        [self dismissViewControllerAnimated:YES completion:^{}];
    }
}
 
Can you show me the code you used in your alertView:clickedButtonAtIndex: that calls dismissViewControllerAnimated:completion:?

I tried the following and it works fine for me:
Code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) {
        NSLog(@"Canceled.");
        [self dismissViewControllerAnimated:YES completion:^{}];
    }
}

That works! I misread the method you suggested and thought it was one of the ones I already tried.

Thanks for your help!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.