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. 
            Asked
            
        
        
            Active
            
        
            Viewed 699 times
        
    0
            
            
         
    
    
        childrenOurFuture
        
- 1,889
- 2
- 14
- 23
 
    
    
        Kamboh
        
- 41
- 7
2 Answers
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
- 
                    OP is looking for a swift syntax I believe by the tag he used. – Jeet Jul 01 '16 at 07:54
- 
                    Thanks for the hint, I added the Swift syntax. – Flo Jul 01 '16 at 08:28
 
    