user941059
user941059

Reputation: 157

Close UIViewController

I'm trying to close soon after a UIViewController call another. It should be simple, but I'm not succeeding. I am using the following method:

- (IBAction)bClose:(id)sender {

    iTest *test = [[iTest alloc] initWithNibName:@"iTest" bundle:[NSBundle mainBundle]];
    test.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:test animated:YES];
    [test release];

    [self dismissModalViewControllerAnimated:YES];
}

Upvotes: 2

Views: 3797

Answers (2)

vakio
vakio

Reputation: 3177

I believe it's not simple. I have done something similar but instead I present the second in the first, then dismiss the first when the second wants to dismiss (dismissing both at the same time). To explain what I mean better:

  1. main -> present controller1
  2. controller1 -> present controller2
  3. controller2 -> dismiss controller1

I'm sure there is a better solution to it though.

Something like this:

inside first controller:

UIViewController *c1 = [[UIViewController alloc] init];
[self presentModalViewController: c1 animated:YES];

inside c1:

UIViewController *c2 = [[UIViewController alloc] init];
c2.c1 = self;
[self presentModalViewController: c2 animated:YES];

inside c2:

[c1 dismissModalViewControllerAnimated:YES];

Upvotes: 1

Shubhank
Shubhank

Reputation: 21805

i also had to try something similar..but ran into much of the same problem..

My solution was to initiate a timer with time 0.5 sec and then dismiss the view in the selector

Worked for me.

Upvotes: 0

Related Questions