LanternMike
LanternMike

Reputation: 664

How to go back to previous view from action sheet

I had my back button on view controller two set to exit the view via dragging from action button to exit on view controller.

I'm trying to do it programatically now. I have

- (IBAction)goBack:(UIButton *)sender {
    NSLog(@"go back");
    //[self.navigationController popViewControllerAnimated:YES];

    [self dismissViewControllerAnimated:TRUE completion:^{
        NSLog(@"Test");

    }];
    NSLog(@"are we back");
}

this:

[self.navigationController popViewControllerAnimated:YES];

didn't seem to do anything. but the current method of dismiss seems to work.

the problem is in my main view i had

-(IBAction) returnToMainView1:(UIStoryboardSegue *) segue
{
    NSLog(@"return to main view");
    self._mytopconsoleview=nil;
    self._mybottomconsoleview=nil;
    self.viewB=nil;
    [self animateRotation:[[UIApplication sharedApplication] statusBarOrientation]];
}

and that is no longer called. How do i dismiss the current view controller and call a method on the main view like the one I have.

Mike

Upvotes: 0

Views: 259

Answers (1)

Aaron Wojnowski
Aaron Wojnowski

Reputation: 6480

Just re-iterating what I said in my comment - which apparently pushed you in the right path :)

Basically, you're looking to move the logic in the returnToMainView1 method to viewDidAppear. This is called whenever a view appears (as its name suggests) such as after dismissing a modal view controller.

Regarding the navigation view scheme, just dismiss based on how you presented. If you used a modal view controller, use dismissViewControllerAnimated:completion or if you used a navigation controller, use popViewControllerAnimated:.

Upvotes: 1

Related Questions