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 11-07-2011, 08:59 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Boulder, CO
Posts: 5
cesky12 is on a distinguished road
Default Table view:how to store accessoryType

Hi,

I am a student taking a mobile apps development class and I've hit a wall with one of my projects:

I have a table view populated by a plist in a modal view. The user can tap on individual cells to toggle the tableViewCellAccessory from "None" to "Checkmark".
What I am trying to do is store the accessory type for each cell so it can be referenced in the previous view.

So far, I have spent time time attempting to store that info in a NSUserDefaults list but I am having no luck. I am pretty confused since the number of cells is dependent on the plist and I need to be able to store the accessory type for each cell and use it in an "if" statement in the previous view.

I would appreciate any help with how to write the code this way or any alternative way to achieve the same results.

I'm new to this so forgive me if I use incorrect terms.

Thank you!!

cesky12
cesky12 is offline   Reply With Quote
Old 11-07-2011, 12:04 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

You're approaching it from the wrong direction. The checkmark is a reflection of your data, not the embodiment of it. You model should have some kind of property in it - shouldBeChecked - and then your table view can read that to know whether or not to display the checkmark. When the user taps a row, change that value.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

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

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 11-08-2011, 12:38 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Boulder, CO
Posts: 5
cesky12 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
You're approaching it from the wrong direction. The checkmark is a reflection of your data, not the embodiment of it. You model should have some kind of property in it - shouldBeChecked - and then your table view can read that to know whether or not to display the checkmark. When the user taps a row, change that value.


Thanks for your reply.

That makes sense, but how would I initially assign that property to each cell in the table?
cesky12 is offline   Reply With Quote
Old 11-08-2011, 01:33 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Do you know how table views work?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

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

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 11-08-2011, 02:10 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Boulder, CO
Posts: 5
cesky12 is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
Do you know how table views work?
In general, yes. I do not, however, know anything about storing or assigning properties to individual cells.
cesky12 is offline   Reply With Quote
Old 11-08-2011, 02:49 PM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

The only thing you're changing about the cell is the accessory type as you mentioned in the first post.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

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

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 11-08-2011, 03:18 PM   #7 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Boulder, CO
Posts: 5
cesky12 is on a distinguished road
Default

Correct, so my code looks like this so the user can check and uncheck cells:


-(void) tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:
indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;

}
else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}

[tableView deselectRowAtIndexPath:indexPath animated:YES];
}



Now I am trying to save that selection using NSUserDefaults so the cells stay checked/unchecked even if the app is exited.
cesky12 is offline   Reply With Quote
Old 11-28-2011, 06:37 PM   #8 (permalink)
Registered Member
 
Join Date: Nov 2011
Location: Boulder, CO
Posts: 5
cesky12 is on a distinguished road
Default

bump
cesky12 is offline   Reply With Quote
Old 11-28-2011, 10:59 PM   #9 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

You've made no progress in 3 weeks?
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

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

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 11-29-2011, 12:15 PM   #10 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

its hard to tell exactly what you are trying to do, but if nothing else it seems like you could create a string representation of each type, then concatenate them together and save them to userDefaults. Then read them back when you need them. Like this:

NSString *types = @"None|Checkmark|Checkmark|Checkmark";

save that string to userDefaults.

then read it back in when the view re-loads and convert it to an array:

NSArray *accessoryTypes = [types componentsSeperatedByString:@"|"];

and finally set the accessoryTypes based on the strings.
RickSDK is offline   Reply With Quote
Reply

Bookmarks

Tags
accessory type, nsuserdefaults, table view

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: 404
16 members and 388 guests
7twenty7, Alex-alex, Apptronics RBC, baja_yu, dre, gwelmarten, ipodphone, jeroenkeij, jleannex55, matador1978, mbadegree, n00b, pbart, Retouchable, Sami Gh, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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