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 07-08-2010, 01:25 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: India
Posts: 28
Sreenivas Reddy is on a distinguished road
Question How do you Save UIButton State to selected when quiting & relaunching app

I'm very new at this. So please be patient with me

I have made a simple Application that has only 1 main view, buttons that turn on and off that represent days. It works perfectly on my iphone and the simulator, but when it closes everything is reset. I just need some help or sample code that will allow the buttons to stay selected when the application quits.

Example - In the MainView.h I have

BOOL checkboxSelected; IBOutlet UIButton *day1;

With an - (IBAction)day1id)sender;

In the MainView.m I have

- (IBAction)day1id)sender{
if (checkboxSelected == 0){
[day1 setSelected:YES];
checkboxSelected = 1;
} else {
[day1 setSelected:NO];
checkboxSelected = 0;

Each button has this code. When a button is pressed an X appears as the selected state. I want it to stay selected when the App is closed and re-opened. Anyone that can help, I'd really appreciate it Thanx in Advanced.
Sreenivas Reddy is offline   Reply With Quote
Old 07-08-2010, 05:35 AM   #2 (permalink)
el guaje
 
kevinyide's Avatar
 
Join Date: Jun 2010
Posts: 243
kevinyide is on a distinguished road
Send a message via Yahoo to kevinyide
Default

is the X that you mention some kind of image or are you changing the button title text?

Save some flag for the buttons that need to be selected upon app relaunch, then depending on flag value for the buttons you could try
Code:
[buttonOutlet setHighlighted:YES];
kevinyide is offline   Reply With Quote
Old 07-08-2010, 05:38 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 172
raziiq is on a distinguished road
Default

Google for NSUserDefaults
raziiq is offline   Reply With Quote
Old 07-08-2010, 05:44 AM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Sreenivas Reddy View Post
I'm very new at this. So please be patient with me

I have made a simple Application that has only 1 main view, buttons that turn on and off that represent days. It works perfectly on my iphone and the simulator, but when it closes everything is reset. I just need some help or sample code that will allow the buttons to stay selected when the application quits.

Example - In the MainView.h I have

BOOL checkboxSelected; IBOutlet UIButton *day1;

With an - (IBAction)day1id)sender;

In the MainView.m I have

- (IBAction)day1id)sender{
if (checkboxSelected == 0){
[day1 setSelected:YES];
checkboxSelected = 1;
} else {
[day1 setSelected:NO];
checkboxSelected = 0;

Each button has this code. When a button is pressed an X appears as the selected state. I want it to stay selected when the App is closed and re-opened. Anyone that can help, I'd really appreciate it Thanx in Advanced.
When the user changes the state of the button, save the selected flag to a key value pair in NSUserDefaults.

In your ViewDidLoad method, load that key/value pair from user defaults and set the selected state of the button using the saved value.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

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: 346
13 members and 333 guests
akacaj, c2matrix, cgokey, esoteric, EXOPTENDAELAX, GHuebner, givensur, HemiMG, Mirotion22, mjnafjke, Pudding, SLIC, Sonuye857
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,652
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Sonuye857
Powered by vBadvanced CMPS v3.1.0

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