Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.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 09-17-2009, 02:21 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 4
Red face NSUserDefaults not setting Toggle Switches in Table!?

Hi,

My root.plist has about 6 PSToggleSwitchSpecifiers. I am trying to access all of them through my application and through a UITableView controller.

I check in viewDidLoad that the UserDefaults are in fact their default values (a couple 1's and a couple 0's). In the cellForRowAtIndexPath method, I use an existing cell or create a cell with a UISwitch in the accessory view. I also give the switch a tag #.

Then, i set the UISwitch (after setting the label text):

UISwitch *switchView = (UISwitch *)[cell viewWithTag:kSwitchTag];
[switchView setOn: [[[NSUserDefaults standardUserDefaults] stringForKey:rowString]intValue] animated:NO];

SO THE QUESTION IS:
The toggle switches all show up OFF when the view loads. However, if I "throw" the screen down in an attempt to scroll (there are only 6 rows so there isn't anywhere to scroll really), the switches set to ON appropriately. How can I get these switches to load properly when the view appears?!!

One more thing, I put [self.tableView reloadData], [self.tableView setNeedsLayout], and [self.tableView setNeedsDisplay] in both viewDidAppear and viewWillAppear methods, and that doesn't work.

Woe is me! Thanks to whoever can help! -Morgan
morgs32 is offline   Reply With Quote
Old 09-17-2009, 02:32 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

I think you want to give the switch a boolean value. Not sure that it works with integer values (haven't tried).
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 09-17-2009, 02:34 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
Default

try

Code:
[switchView setOn: [[[NSUserDefaults standardUserDefaults] stringForKey:rowString] boolValue] animated:NO];
dancriel is offline   Reply With Quote
Old 09-24-2009, 11:11 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 4
Default

You're both right, I should have been using bool values. I was going back and forth between bool and integers (and somehow it was working anyway).

Still, however, I have to throw the screen down to see the switches set to their proper (persisted) values. I have tried "reload" and "needslayout" etc. It sounds like only the reused table cells are showing the proper value? But when I first create a cell it doesn't. I'll post the code as soon as I get home.

Anyone seen this before?
morgs32 is offline   Reply With Quote
Old 09-24-2009, 11:14 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2009
Location: Philadelphia, PA
Posts: 154
Default

have you tried [tableView reloadData]
dancriel is offline   Reply With Quote
Reply

Bookmarks

Tags
nsuserdefaults, seton, settings, table, uiswitch

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: 242
12 members and 230 guests
ADY, AragornSG, CKAmike, Dani77, Duncan C, HemiMG, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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