0

I want to create a new App. How can I open a new ViewController automatically after a certain time i-e 5 seconds.
Please explain answer because I'm new on XCode.

childrenOurFuture
  • 1,889
  • 2
  • 14
  • 23
Kamboh
  • 41
  • 7

2 Answers2

1

You can use the class NSTimer for this. The following line of code schedules a certain method to be called after a certain time (3 seconds):

[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(myMethod) userInfo:nil repeats:NO];

In the method myMethod, you can simply push a new view controller:

- (void)myMethod
{
    UIViewController *vc = [[UIViewController alloc] init];
    [self pushViewController:vc animated:YES];
    [vc release];
}

Edit: Here's how you can do it with Swift:

var timer = NSTimer.scheduledTimerWithTimeInterval(3.0, target: self, selector: #selector(MyClass.myMethod), userInfo: nil, repeats: false)

func myMethod() 
{
    let vc = UIViewController.init()
    self.pushViewController(vc!, animated: true)
}
Flo
  • 2,309
  • 20
  • 27
0

You can use present view controller after time. Please refer to this SO Thread for details.

BR

Community
  • 1
  • 1
Jeet
  • 5,569
  • 8
  • 43
  • 75