How to change view automatically

Joined
Feb 21, 2011
Messages
22
Reaction score
0
Points
1
Your Mac's Specs
Macbook Air 11", 64 GB, Intel core i5, 1.6 GHz, OSX Lion 10.7
Hello everyone,

My this app consists of 5 views. each view has a button that switches to the next view. now I want to add one more view. but this time I don't want to press a button to go to the 6th view. what I want is, I press a button on view 4 that switches to view 5 then view 5 waits for say 2 seconds or 5 seconds or whatever, then it automatically switches to the view 6. can I add a counter?? How can it be done??
Please guide me....

Thanks and regards

Prateek Chaubey
 

bobtomay

,
Retired Staff
Joined
Dec 22, 2006
Messages
26,561
Reaction score
677
Points
113
Location
Texas, where else?
Your Mac's Specs
15" MBP '06 2.33 C2D 4GB 10.7; 13" MBA '14 1.8 i7 8GB 10.11; 21" iMac '13 2.9 i5 8GB 10.11; 6S
Note: Moved to appropriate forum.
 
Joined
Apr 2, 2011
Messages
18
Reaction score
0
Points
1
Location
Tennessee
Your Mac's Specs
2011 15" Macbook pro 2.2Gh Quad Core 8GB RAM and 2009 27" iMac 2.93Ghz ( Custom Mod ) Quad core and
How to auto switch views

You could call a NSTimer and when timer fires call your method for switching views EX.

in your .H file

@interface TestViewController : UIViewController {
NSTimer *SwitchTimer;

}

@property (nonatomic, retain) NSTimer *SwitchTimer;

@end


Now in your .M file


#import "TestViewController.h"

@implementation TestViewController
@synthesize SwitchTimer;


- (void)viewDidLoad
{
[super viewDidLoad];

SwitchTimer =[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:mad:selector(SwitchViews:) userInfo:nil repeats:NO];
}

-(void)SwitchViews:(id)sender
{
// Now call your methode you use to switch views
}



- (void)dealloc
{
[super dealloc];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle


@end

And Thats that :) just add whats in red
 
Joined
Apr 2, 2011
Messages
18
Reaction score
0
Points
1
Location
Tennessee
Your Mac's Specs
2011 15" Macbook pro 2.2Gh Quad Core 8GB RAM and 2009 27" iMac 2.93Ghz ( Custom Mod ) Quad core and
You could call a NSTimer and when timer fires call your method for switching views EX.

in your .H file

@interface TestViewController : UIViewController {
NSTimer *SwitchTimer;

}

@property (nonatomic, retain) NSTimer *SwitchTimer;

@end


Now in your .M file


#import "TestViewController.h"

@implementation TestViewController
@synthesize SwitchTimer;


- (void)viewDidLoad
{
[super viewDidLoad];

SwitchTimer =[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:mad:selector(SwitchViews:) userInfo:nil repeats:NO];
}

-(void)SwitchViews:(id)sender
{
// Now call your methode you use to switch views
}



- (void)dealloc
{
[super dealloc];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}

#pragma mark - View lifecycle


@end

And Thats that :) just add whats in red

that frownie face isn't suposed to be there in the -(Void)SwitchViews just take out the frownie and put --:( where it was between the s and i * Dont put where its brown thats just so that it doesnt think it s a frownie again :)
 
OP
P
Joined
Feb 21, 2011
Messages
22
Reaction score
0
Points
1
Your Mac's Specs
Macbook Air 11", 64 GB, Intel core i5, 1.6 GHz, OSX Lion 10.7
Hi Alex,

First of all thank you very much for your help. Now, I reduced the views from 6 to 3. I applied your code on view 2. I am pressing a button on view 1 that switches to view 2 and starts the timer. But instead of going to view 3 the application gets terminated. I double checked my code but could not find a solution. Please help.

Thanks and regards..
Prateek Chaubey
 
Joined
Apr 2, 2011
Messages
18
Reaction score
0
Points
1
Location
Tennessee
Your Mac's Specs
2011 15" Macbook pro 2.2Gh Quad Core 8GB RAM and 2009 27" iMac 2.93Ghz ( Custom Mod ) Quad core and
Hi Alex,

First of all thank you very much for your help. Now, I reduced the views from 6 to 3. I applied your code on view 2. I am pressing a button on view 1 that switches to view 2 and starts the timer. But instead of going to view 3 the application gets terminated. I double checked my code but could not find a solution. Please help.

Thanks and regards..
Prateek Chaubey

When I posts the code Mac-Forums test editor turned some symbols into smilie and frownie faces lol but I can't figure out how to get them to go away ? Key where there is a frownie face there is supposed to be a : and a open parentheses (... and where there is a smilie far there is supposed to be a : and a close parentheses ) ...
 
Joined
May 14, 2009
Messages
2,052
Reaction score
136
Points
63
Location
Near Whitehorse, Yukon
Your Mac's Specs
2012 MBP i7 2.7 GHz 15" Matte - 16 GB RAM - 120 GB Intel SSD - 500 GB DataDoubler Mac OS 10.9
You can put code in the code tags [*CODE]Hello world![*/CODE] (Minus the * symbols). That way it will stay formatted as you paste it.
 
OP
P
Joined
Feb 21, 2011
Messages
22
Reaction score
0
Points
1
Your Mac's Specs
Macbook Air 11", 64 GB, Intel core i5, 1.6 GHz, OSX Lion 10.7
Hey Alex,

Those smilies were not a problem. It was some other mistake. I found it out and now the app runs..
Thanks for your support

regards
Prateek
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top