Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 10    Views: 100

Uelsimon
Lost but trying
Profile
Posts: 272
Reg: Mar 25, 2012
NYC
4,470
10/13/14 01:47 PM (9 years ago)

How do I make a loop work between screens without resetting on each load.

ok..forgive me for the remedial question..but heres what I’m trying to do. 1. trigger an action every 5 times that an button is pressed. 2. keep count even if the user leaves the screen this is what i originally tried. in the .m file I placed in the method for the action //loop to trigger easer egg int adfrequency = 2; int count = 0; if(count == adfrequency) { [trigger easer egg]; count = 0; } else { count++; } but I think every time I load the page…the count resets to 0. so it never triggers the easter egg. I know I need to some how store the value for count outside the .m file and retrieve it each time..or something so that it doesn’t reset each time. anyone know the answer to this real simply? thanks
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
10/13/14 02:19 PM (9 years ago)
Hi mate! Once the app closes it's probably resetting/releasing your stored variables, as it should. There are other methods to retaining data once the user leaves, for example, NSUserDefaults. If you can't find the solution and you've tried everything else, feel free to email me. Until then, let's see if the community can help you. Look up NSUserDefaults, it's really flexible, but may require some tweaking to get it to do what you want, which is make your data persistent. Sorry I couldn't be more help! David Van Beveren http://btmods.com/chat ^ Chat with other BT members live! http://btmods.com/hire ^ Hire MrDavid for one of his services!
 
PSMDanny
Apple Fan
Profile
Posts: 1166
Reg: Dec 09, 2011
Heerlen
21,940
like
10/13/14 02:20 PM (9 years ago)
Hi Simon, Read about NSUserDefault here: www.codigator.com/snippets/nsuserdefaults-tutorial-for-ios/ So create an integer with a value of zero and set that to the NSUserdefault value In your button click event raise that value with 1 So every time the button is clicked 1 gets added to the integer value. In your button click event create an if else structure where you say: if integer is equal to 5 do this 'function' (and set the integer value to zero again) else do that 'function' I have no code to show but this should be the way. I hope this helps. Best Regards, Danny
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
10/13/14 02:27 PM (9 years ago)
Danny and I are on the same page today :-) Cheers, David Van Beveren http://btmods.com/chat ^ Chat with other BT members live! http://btmods.com/hire ^ Hire MrDavid for one of his services!
 
Uelsimon
Lost but trying
Profile
Posts: 272
Reg: Mar 25, 2012
NYC
4,470
like
10/13/14 03:33 PM (9 years ago)
I like... will give it a try. Thanks guys. sometimes just having someone to help think about it in a different way makes a huge difference €
 
Uelsimon
Lost but trying
Profile
Posts: 272
Reg: Mar 25, 2012
NYC
4,470
like
10/13/14 04:53 PM (9 years ago)
I like... will give it a try. Thanks guys. sometimes just having someone to help think about it in a different way makes a huge difference €
 
Uelsimon
Lost but trying
Profile
Posts: 272
Reg: Mar 25, 2012
NYC
4,470
like
10/13/14 09:56 PM (9 years ago)
Thanks guys…finally figured it out…thanks for the trail hints. NSUserDefault + Youtube search = PROBLEM SOLVED €
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
10/13/14 10:31 PM (9 years ago)
Rockstar! Congratulations! Cheers, David Van Beveren http://btmods.com/chat ^ Chat with other BT members live! http://btmods.com/hire ^ Hire MrDavid for one of his services!
 
Kittsy
buzztouch Evangelist
Profile
Posts: 2251
Reg: Feb 22, 2012
Liverpool
31,360
like
10/14/14 08:13 AM (9 years ago)
Just for information. Benefits you can access this globally around the app with alot more ease. Buzztouch has helper methods for nsuserdefaults mainly used for strings Set [BT_strings setPrefString:@"count" valueOfPref: @"1"]; Get [BT_strings getPrefString:@"count"]; It uses nsstring but can be accessed using casting thus Get as an int [[BT_strings getPrefString:@"count"]intValue];
 
Uelsimon
Lost but trying
Profile
Posts: 272
Reg: Mar 25, 2012
NYC
4,470
like
10/14/14 08:18 AM (9 years ago)
hmmm...nice very nice. thanks €
 
mrDavid
BTMods.com
Profile
Posts: 3936
Reg: May 21, 2011
San Diego, CA
51,910
like
10/23/14 12:09 PM (9 years ago)
Sent you an email Kittsy regarding your last little tip! Cheers, David Van Beveren http://btmods.com/chat ^ Chat with other BT members live! http://btmods.com/hire ^ Hire MrDavid for one of his services!
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.