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 05-24-2011, 09:32 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default UISwitch in UITableView reset while scrolling

Hi

I have a UITableview with custom cells in it. One of the customcell has a UISWITCH in it. When the scroll the table view the state of the switch gets reset even if I set it to ON. How can I maintain the state of the switch during scroll. Any help is appreciated.

Thanks
vikinara is offline   Reply With Quote
Old 05-24-2011, 10:34 PM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

What you probably mean is, not when you scroll, but when the cell needs to be displayed again after being scrolled off the screen.

The answer is, don't store state in your table view cells. Define a model to store everything. The cells will come and go, and you will lose information if you rely on them sticking around.

The backing store for your data will depend on your needs and preferences. Could be a SQLite database, could be a plist, could be NSUserDefaults.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 05-25-2011, 03:42 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

I have this method hooked up to the switch. It works fine but when i scroll it gets reset to the original OFF state and the data disappears. please give me some suggestions.

-(IBAction)sameDriverid)sender{

if ([sender isOn]){

NSLog(@"%@",(otherdriver.drive ? @"YES" : @"NO"));

NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool: YES forKey: K_SWITCH_KEY];
[defaults synchronize];

Switchon = [defaults boolForKey: K_SWITCH_KEY];


if(Switchon){

otherdriver.dfname.text = fname;
otherdriver.dlname.text = lname;
otherdriver.demail.text = email;
otherdriver.dpnum.text = phone;

}
}
else if(![sender isOn]){

NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool: NO forKey: K_SWITCH_KEY];
[defaults synchronize];

NSLog(@"%@",(otherdriver.drive ? @"YES" : @"NO"));

Switchon = [defaults boolForKey: K_SWITCH_KEY];

otherdriver.dfname.text = drfname;
otherdriver.dlname.text = drlname;
otherdriver.demail.text = dremail;
otherdriver.dpnum.text = drphone;


}}
vikinara is offline   Reply With Quote
Old 05-25-2011, 03:48 PM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Jan 2010
Location: Issaquah, WA
Age: 42
Posts: 1,244
dljeffery is on a distinguished road
Default

Show your implementation of cellForRowAtIndexPath.
__________________
Recall It! Tag your notes. Tag your photos. Tag your thoughts. Tag your life.

Recall It! for iPad

http://www.dljeffery.com
dljeffery is offline   Reply With Quote
Old 05-25-2011, 03:54 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 84
vikinara is on a distinguished road
Default

Quote:
Originally Posted by dljeffery View Post
Show your implementation of cellForRowAtIndexPath.
I have got the switch in the IB and linked the method to it. I have not done anything in the cellforRowIndexPath. I dont know how to do it. Could you please help me.
vikinara is offline   Reply With Quote
Old 05-26-2011, 02:47 AM   #6 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Quote:
Originally Posted by vikinara View Post
I have got the switch in the IB and linked the method to it. I have not done anything in the cellforRowIndexPath. I dont know how to do it. Could you please help me.
so the UISwitch is not on UITableView......

My advice is to start reading a book, you miss some basics concepts....

Start from this tutorial about UITableView
http://www.iphonedevsdk.com/forum/ip...ew-series.html
__________________
dany_dev is offline   Reply With Quote
Reply

Bookmarks

Tags
uiswitch, uitableview, uitableviewcell

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: 364
7 members and 357 guests
doffing81, dre, iOS.Lover, jenniead38, Kirkout, PlutoPrime, Wikiboo
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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