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-09-2010, 01:53 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Location: India
Posts: 28
Sreenivas Reddy is on a distinguished road
Question save/retrieve UIButton state

Hi in my app i want to save and retrieve button state how can i do

i am using two images for button select.png and nonselect.png

pls help

Last edited by Sreenivas Reddy; 07-10-2010 at 12:54 AM.
Sreenivas Reddy is offline   Reply With Quote
Old 07-09-2010, 02:12 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2009
Location: india
Posts: 65
sharhelia is on a distinguished road
Default reply

Quote:
Originally Posted by Sreenivas Reddy View Post
Hi in my app i want to save and retrieve button state how can i do

i am using two images for button select.png and nonselect.png

pls help

i am getting with NSUserDefault

hi
You can save the state of the button using like
if([btn currentimae] == [uiimage imagenamed:@"select.png"])
{
// selected and save to nsuserdefaults
}
else
{
// not selected and save unselected to nsuserdefaults
}

in this way you can find the state of button

hope it ll help u

}
sharhelia is offline   Reply With Quote
Old 07-09-2010, 02:13 AM   #3 (permalink)
Registered Member
 
macoholic's Avatar
 
Join Date: Dec 2008
Location: around a Mac...in Pune,India :)
Posts: 137
macoholic is on a distinguished road
Default

Can you elaborate please ?
Developers here will be help if they understand your problem better.
In turn it helps all of us!!

Cheers,
macoholic
macoholic is offline   Reply With Quote
Old 07-09-2010, 02:23 AM   #4 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 30
Reena Mehta is on a distinguished road
Default

Quote:
Originally Posted by Sreenivas Reddy View Post
Hi in my app i want to save and retrieve button state how can i do

i am using two images for button select.png and nonselect.png

pls help

i am getting with NSUserDefault
Hi,

You can try this,

Code:
	[btn setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"select" ofType:@"png"]] forState:UIControlStateNormal];  
	[btn setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"nonselect" ofType:@"png"]] forState:UIControlStateSelected];
Reena Mehta is offline   Reply With Quote
Old 07-09-2010, 07:55 AM   #5 (permalink)
Registered Member
 
Join Date: Apr 2010
Location: Milano
Posts: 99
zero_ is on a distinguished road
Default

there's a simple way withoun nsuserdefault: use the (id)sender


Code:
	if ([sender isSelected]) 
	{
		[sender setImage:[UIImage imageNamed:@"notselect.png"] forState:UIControlStateNormal ];
		[sender setSelected:NO];
	}else 
	{
		[sender setImage:[UIImage imageNamed:@"selected.png"] forState:UIControlStateSelected];
		[sender setSelected:YES];
	}
}
zero_ 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: 337
13 members and 324 guests
akphyo, cgokey, EXOPTENDAELAX, flamingliquid, GHuebner, guusleijsten, ohmniac, Paul Slocum, PavelSea, SLIC, Sloshmonster, Sonuye857, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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