05-05-2011, 04:17 PM
#1 (permalink )
Registered Member
Join Date: Mar 2010
Location: Tennessee
Posts: 23
Make a UIViewController appear only once
Hi everyone,
I'm creating an application in which I have a particular view, but I'd like that view to appear only the first time the application is loaded. This is the code I'm using now, but it's not working out to well. I have this code in the viewDidLoad of the initial ViewController.
Code:
- (void)viewDidLoad
{
if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"ArrowFirst"]]) {
[[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"ArrowFirst"];
[[NSUserDefaults standardUserDefaults] synchronize];
MathViewController *math = [[MathViewController alloc] initWithNibName:@"MathViewController" bundle:nil];
UIView *currentView = self.view;
UIView *theWindow = [currentView superview];
UIView *newView = math.view;
[currentView removeFromSuperview];
[theWindow addSubview:newView];
CATransition *animation = [CATransition animation];
[animation setDuration:1.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[[theWindow layer] addAnimation:animation forKey:@"ChangeViews"];
[math release];
}
else{
}
[super viewDidLoad];
}
Last edited by DevinSnipes; 05-05-2011 at 04:25 PM .
05-05-2011, 04:23 PM
#2 (permalink )
Reading the Documentation
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
Please use [code] tags. Whenever I see a bunch of code like that I immediately lose interest in reading the post.
05-05-2011, 04:25 PM
#3 (permalink )
Beast Mode
Join Date: Dec 2008
Age: 21
Posts: 1,971
Quote:
Originally Posted by
DevinSnipes
Hi everyone,
I'm creating an application in which I have a particular view, but I'd like that view to appear only the first time the application is loaded. This is the code I'm using now, but it's not working out to well. I have this code in the viewDidLoad of the initial ViewController.
- (void)viewDidLoad
{
if (![@"1" isEqualToString:[[NSUserDefaults standardUserDefaults] objectForKey:@"ArrowFirst"]]) {
[[NSUserDefaults standardUserDefaults] setValue:@"1" forKey:@"ArrowFirst"];
[[NSUserDefaults standardUserDefaults] synchronize];
MathViewController *math = [[MathViewController alloc] initWithNibName:@"MathViewController" bundle:nil];
UIView *currentView = self.view;
UIView *theWindow = [currentView superview];
UIView *newView = math.view;
[currentView removeFromSuperview];
[theWindow addSubview:newView];
CATransition *animation = [CATransition animation];
[animation setDuration:1.5];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
[[theWindow layer] addAnimation:animation forKey:@"ChangeViews"];
[math release];
}
else{
}
[super viewDidLoad];
}
First, Please use code tags...
Second, Is it the animation code that is not working or is it the check to see if it should show the view that is not working?
__________________
Haters gonna Hate
Likers gonna Like
05-05-2011, 04:26 PM
#4 (permalink )
Registered Member
Join Date: Mar 2010
Location: Tennessee
Posts: 23
Quote:
Originally Posted by
Bertrand21
First, Please use code tags...
Second, Is it the animation code that is not working or is it the check to see if it should show the view that is not working?
I've updated this post with the code tags, I apologize for that. The animation code is working properly, it's just the check to see if the view should show.
05-05-2011, 04:44 PM
#5 (permalink )
Beast Mode
Join Date: Dec 2008
Age: 21
Posts: 1,971
Quote:
Originally Posted by
DevinSnipes
I've updated this post with the code tags, I apologize for that. The animation code is working properly, it's just the check to see if the view should show.
Heres how I do mine:
Code:
-(BOOL)getShownHelpDialog{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSNumber *preference = [prefs objectForKey:@"ShownHelpDialog"];
if(preference == nil){
return NO;
}
else{
return [preference boolValue];
}
}
-(void)setShownHelpDialog:(BOOL)preference{
NSNumber *pref = [NSNumber numberWithBool:preference];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:pref forKey:@"ShownHelpDialog"];
[prefs synchronize];
}
in your viewDidLoad or viewDidAppear...
Code:
if(![self getShownHelpDialog]){
//Show the view here...
[self setShownHelpDialog:YES];
}
__________________
Haters gonna Hate
Likers gonna Like
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 354
10 members and 344 guests
dansparrow , iOS.Lover , lorrettaui53 , MikaelBartlett , Nobbsy , oztemel , pbart , PlutoPrime , thephotographer , Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44