Blazer
Blazer

Reputation: 14277

After NStimer new screen

Is there a way to open a new screen after the NStimer is on 0?

e.x:

-(void) randomMainVoid {

   if (mainInt <= 0)
    {
        [randomMain invalidate];

        //after counting a code to open a new file (new .h/.m/.xib file)

    } else {

    //something

    }
}

Upvotes: 0

Views: 106

Answers (1)

Jason Coco
Jason Coco

Reputation: 78363

If you're using the standard view controller/nib model, it's pretty easy to load a new screen. How you present it, however, will really depend on your application. But, as an example, if you wanted to present a new modal screen after the timer finished, and you had a view controller class named AfterTimerViewController with an associated nib file, you would present it as such:

-(void) randomMainVoid
{
  if (mainInt <= 0) {
    [randomMain invalidate];

    // This assumes this method is defined in the current view
    // controller. If not, replace self with the appropriate reference
    AfterTimerViewController* controller = [[AfterTimerViewController alloc] initWithNibName:@"AfterTimerViewController" bundle:nil];
    // Uncomment and use for pushing onto a navigation controller's stack
    [[self navigationController] pushViewController:controller animated:YES];

    // Uncomment and use if you want the new view controller to replace the root of your
    // current navigation controller stack
    //[[self navigationController] setViewControllers:[NSArray arrayWithObject:controller] animated:YES];

    // Uncomment and use for presenting the new controller as a modal view controller
    //[self presentModalViewController:controller animated:YES];

    [controller release]; // change this if you're using ARC or taking ownership of this controller accordingly
  } else {
    //something
  }
}

For more information on these methods, see the UIViewController documentation and the View Controller Programming Guide for iOS.

edit: I added sample code for a number of different common transitions. The best thing to do is to read the guides about View Controllers and their interactions so that you can use the pattern that best fits the design of your application. In general, tho, the sample code above shows how to react to events, create a view controller programmatically and present it.

Upvotes: 1

Related Questions