Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-05-2011, 04:17 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Tennessee
Posts: 23
DevinSnipes is on a distinguished road
Default 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];
    
}
__________________
-Regards,

Devin Snipes
My Website
Follow Me on Twitter

My AppStore Apps:
Am I Ugly(Free)
uChat For iPhone(Free)
MCS For iPhone(Free)

Last edited by DevinSnipes; 05-05-2011 at 04:25 PM.
DevinSnipes is offline   Reply With Quote
Old 05-05-2011, 04:23 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Please use [code] tags. Whenever I see a bunch of code like that I immediately lose interest in reading the post.
baja_yu is offline   Reply With Quote
Old 05-05-2011, 04:25 PM   #3 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by DevinSnipes View Post
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
Bertrand21 is offline   Reply With Quote
Old 05-05-2011, 04:26 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Tennessee
Posts: 23
DevinSnipes is on a distinguished road
Default

Quote:
Originally Posted by Bertrand21 View Post
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.
__________________
-Regards,

Devin Snipes
My Website
Follow Me on Twitter

My AppStore Apps:
Am I Ugly(Free)
uChat For iPhone(Free)
MCS For iPhone(Free)
DevinSnipes is offline   Reply With Quote
Old 05-05-2011, 04:44 PM   #5 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,971
Bertrand21 is on a distinguished road
Default

Quote:
Originally Posted by DevinSnipes View Post
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
Bertrand21 is offline   Reply With Quote
Reply

Bookmarks

Tags
nsuserdefaults, view controller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» 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
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:56 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0