|
|
#1 |
|
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;
}
|
|
|
|
0
|
|
|
#2 |
|
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.
|
|
|
|
0
|
|
|
#3 |
|
ya i am actually continuously creating and destroying it lol how can i make it happen viewWillAppear causes a crash :P
|
|
|
|
0
|
|
|
#4 |
|
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.
|
|
|
|
0
|
|
|
#5 |
|
I LOVE YOU thanks for helping dude putting the NSUInteger out of the @implementation worked great lol how do people know this stuff?
|
|
|
|
0
|
|
|
#6 |
|
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
|
|
|
|
0
|
|
|
#7 |
|
nevermind i got it XD
|
|
|
|
0
|
|
|
#8 |
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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.







Linear Mode

