0

I am making an application using two view controlers. When I am working on my first view I have posibility to go to another view using button "Settings" and method conected to this button looks like this:

-(IBAction)Settings:(id)sender{

[self presentModalViewController:settingsHandle animated:YES];

settingsHandle is an object of a second view class which is alloceted when the first view is loaded.

My problem starts while I am in a second view and i call method which include NSTimer object. This method is working during hmmm lets say 30 sec but it also can be 5 min, the result of this method is calling onother view the 3rd one.

Everything goes fine while am waiting for the result of this function in a second view.The result is that i am in a 3rd view.

When, during the method is working I am going to the first view from the second (using [self dismissModalViewControllerAnimated:YES]; )I can see that the method has finished(using NSLOG) but [self presentModalViewController:thirdview animated:YES]; is not working, just nothing happens.

so to sum up:

Waiting for the result in a secodnview (Succes third view uploaded) Waiting for the result in a firstview (fail nothing happens)

And my goal is to make it happens from the firstview!

user1246957
  • 103
  • 2
  • 8

1 Answers1

0

You can't present a ModalViewController from a ViewController that is dismissed. So, you need to keep track of the visible ViewController and call presentModalViewController from there. In your scenario, the easiest solution would be to make your NSTimer invoke a method in your first ViewController which goes like this

- (void)presentViewController:(NSTimer *)timer
{
    if(self.modalViewController == nil)
        [self presentModalViewController:settingsHandle animated:YES];
    else
        [self.modalViewController presentViewController];
}

If you create the NSTimer in your 2. ViewController, you would of course need a reference to the first ViewController. You could just pass this reference like this

-(IBAction)Settings:(id)sender{
    settingsHandle.myParentViewController = self; //You need to create this var in settingsHandle
    [self presentModalViewController:settingsHandle animated:YES];
    //...
}
Philipp Schlösser
  • 5,179
  • 2
  • 38
  • 52