-2

I'm new to iPhone development and I'm running iOS 6.1. I have two View Controllers called firstViewController and secondViewController. I need to call one view controller from another view controller after 1000 milliseconds without any click of a button, imageView etc.

How is it possible?

Anil
  • 2,430
  • 3
  • 37
  • 55
AppStore
  • 53
  • 6

6 Answers6

2

You can use the code like this

NSTimer *timer;

timer=[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(touchDetected) userInfo:nil repeats:NO];// because 1000 miliseconds=10 sec

In the touchDetected Method put your code

-(void)touchDetected
{
    LoginPage * loginPageObj=[[LoginPage alloc]initWithNibName:@"LoginPage" bundle:nil];
    [self.navigationController pushViewController:loginPageObj animated:YES];
    [timer invalidate];
}

Here you can use code according to you like change the method name and ViewControllers name.

Hope this helps.

iEinstein
  • 2,100
  • 1
  • 21
  • 32
  • your answer is true ,but how to decalre LoginPage? – AppStore Jun 03 '13 at 06:33
  • That's your view controller you want to push. Please give here the name of View Controller you want to push. BTw sorry to be rude but you didn't check my answer carefully "Here you can use code according to you like change the method name and ViewControllers name." I have written – iEinstein Jun 03 '13 at 06:36
1

you can use this method

 [self performSelector:@selector(methodToCall:) withObject:nil afterDelay:1000.0];
Sunny Shah
  • 12,990
  • 9
  • 50
  • 86
1

try with

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


     -(void)pushView {

         SeconViewController *SeconViewControllerObj=[[SeconViewController alloc] initWithNibName:@"SeconViewController" bundle:nil];
         [self.navigationController pushViewController:SeconViewControllerObj animated:YES];
     }
SAMIR RATHOD
  • 3,512
  • 1
  • 20
  • 45
0

You can call a Selector (Method) using NSTimer after a certain time using this -

[NSTimer scheduledTimerWithTimeInterval:<#(NSTimeInterval)#> target:<#(id)#> selector:<#(SEL)#> userInfo:<#(id)#> repeats:<#(BOOL)#>];
saadnib
  • 11,145
  • 2
  • 33
  • 54
0

what you need is a methode, lets call it

-(void)pushNextVC;

and the call

[self performSelector:@selector(pushNextVC) withObject:nil afterDelay:<#(NSTimeInterval)#>];

also possible are solutions with NSTimer, but for this the "performSelector" is enought :)

geo
  • 1,781
  • 1
  • 18
  • 30
0

You can make use of

 [self performSelector:@selector(gotoNextView) withObject:nil afterDelay:]
Anil Varghese
  • 42,757
  • 9
  • 93
  • 110