Ti Amo Laky
Ti Amo Laky

Reputation: 765

redrection the view after 3 seconds to anther view

i create application for iphone with xcode 5,1 and ios 6,0

I want to create a view that contains the name of my application after 3 seconds this view will be redirect to another view that contains processing my application

My Main.storyboard like this enter image description here

In My Class Icoz i have

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"yesss");
    Demmarage *d = [[Demmarage alloc] init];
    [self.navigationController pushViewController:d animated:YES];
    NSLog(@"merdeee");
}

but nothing happend when i build my application

How I can execute my application i want have the view "icoz" for 3 sec & after i want show the view "myblan"

Upvotes: 1

Views: 536

Answers (5)

Arjuna
Arjuna

Reputation: 727

Use this

(void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay;

Upvotes: 0

Alexander
Alexander

Reputation: 7238

First of all, I can not see if your initialViewController is a UINavigationViewController. If not, your statemant self.navigationController is nil which might be the reason why nothing happens"

In your storyboard a segue is visible, you can perform this segue delayed within your viewDidAppear:

- (void)viewDidAppear:(BOOL)animated 
{
    [super viewDidAppear:animated];

    double delayInSeconds = 3.0; //seconds to wait
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [self performSegueWithIdentifier:@"TheNameOfTheSegue" sender:self];
    });
}

Another option, without the GCD and without a segue would be the following – simply pushing by using a navigation controller:

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(pushDemmarage:) userInfo:nil repeats:NO];
    //or use the following line instead of NSTimer
    //[self performSelector:@selector(pushDemmarage:) withObject:nil afterDelay:3];
}

-(void)pushDemmarage:(id)sender
{
    Demmarage *d = [[Demmarage alloc] init];
    [self.navigationController pushViewController:d animated:YES];
}

Upvotes: 4

Jitendra
Jitendra

Reputation: 5081

self.timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(callMethod) userInfo:nil repeats:NO];

-(void)callMethod
{

    // Do what u want here.
    Demmarage *d = [[Demmarage alloc] init];
    [self.navigationController pushViewController:d animated:YES];

}

Try this code..

Upvotes: 0

Anil Varghese
Anil Varghese

Reputation: 42987

You can use a NSTimer to stay in the first controller for 3seconds. Do this in your first controller

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    self.timer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(loadSecondViewController:) userInfo:nil repeats:NO];

}

-(void)loadSecondViewController:(id)sender
{
    [self performSegueWithIdentifier:SecondViewSegueIdentifier sender:self];

}

Here MPSecondViewSegueIdentifier is the segue between first and second view controllers

Upvotes: 0

Pancho
Pancho

Reputation: 4143

In your FirstViewController

-(void)viewDidAppear:(BOOL)animated
{
 //push you secondview controller on GCD with delay
 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3*NSEC_PER_SEC)), dispatch_get_main_queue(),^{
  Demmarage *d = [[Demmarage alloc] init];
  [self.navigationController pushViewController:d animated:YES];

 });
}

Upvotes: 0

Related Questions