Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 14, 2009, 10:01 PM   #1
mandude
macrumors member
 
Join Date: Nov 2009
Help Adding NSUInteger to Label

he i need help adding an NSUInteger number to my label by +1 everytime the view loads.. so the first time you see the view load the label says "1" the next time it loads the label says "2" then "3" and "4" and so on. thanks
Code:

h.file:


@implementation....... {
	NSUInteger levelNumber;
        NSString *string;
        UILabel *label;
}
@property (nonatomic, retain) IBOutlet UILabel *label;
@property (nonatomic, retain) NSString *string;
@end

m. file:

-(void)viewDidLoad {
	levelNumber = levelNumber +1;
	string = [NSString stringWithFormat:@"%d", levelNumber];
	label.text = string;
}
mandude is offline   0 Reply With Quote
Old Dec 14, 2009, 10:02 PM   #2
kainjow
Demi-God (Moderator emeritus)
 
kainjow's Avatar
 
Join Date: Jun 2000
Well it depends how you're using the view controller. If you keep creating it and destroying it, the number will never increment. You could make it static, or you could save it in NSUserDefaults. Or if you're keeping the controller in memory, try overriding viewWillAppear instead of viewDidLoad.
kainjow is offline   0 Reply With Quote
Old Dec 14, 2009, 10:05 PM   #3
mandude
Thread Starter
macrumors member
 
Join Date: Nov 2009
ya i am actually continuously creating and destroying it lol how can i make it happen viewWillAppear causes a crash :P
mandude is offline   0 Reply With Quote
Old Dec 14, 2009, 10:07 PM   #4
kainjow
Demi-God (Moderator emeritus)
 
kainjow's Avatar
 
Join Date: Jun 2000
If you want the value saved for when the app quits, read and write it to NSUserDefaults. If you just want it to increment only while the app is active, simplest way is to move NSUInteger levelNumber; outside of the @interface and make it static.
kainjow is offline   0 Reply With Quote
Old Dec 14, 2009, 10:10 PM   #5
mandude
Thread Starter
macrumors member
 
Join Date: Nov 2009
I LOVE YOU thanks for helping dude putting the NSUInteger out of the @implementation worked great lol how do people know this stuff?
mandude is offline   0 Reply With Quote
Old Dec 14, 2009, 10:13 PM   #6
mandude
Thread Starter
macrumors member
 
Join Date: Nov 2009
ok just a tiny drop more help :P so when i quit the view... go into a different view... and go back into my Label view.. the label adds the number to it. great. now when i quit into a totally different NIB... we'll call that "NIB X" how can i make it that when i go back into the label NIB from "NIB X" that label goes all the way back to 1
mandude is offline   0 Reply With Quote
Old Dec 14, 2009, 10:18 PM   #7
mandude
Thread Starter
macrumors member
 
Join Date: Nov 2009
nevermind i got it XD
mandude is offline   0 Reply With Quote
Old Dec 15, 2009, 03:43 AM   #8
Luke Redpath
macrumors 6502a
 
Join Date: Nov 2007
Quote:
Originally Posted by mandude View Post
lol how do people know this stuff?
They learn how to read the documentation and learn the basics.
Luke Redpath is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Help adding shadowbox to iweb html dave12345 Web Design and Development 3 Nov 8, 2009 02:28 PM
need quick help adding music to slideshow old cholo Digital Video 2 Oct 24, 2009 04:00 PM
Need help adding pictures to camera roll anth007 iPhone Tips, Help and Troubleshooting 3 Aug 28, 2009 05:22 AM
help adding WMA to itunes - I have added a bunch already but it stopped working brvheart Mac Basics and Help 10 Jun 30, 2008 02:05 PM
Need help adding loops to GarageBand AlmightyG5 Mac Applications and Mac App Store 1 Jan 27, 2006 09:15 PM


All times are GMT -5. The time now is 04:02 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC