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 10-08-2009, 08:57 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 5
Default saving NSMutable Array containing View Controllers

I am new to ObjC and iPhone SDK so I am learning by tinkering with the sample code.
I took UICatalog and added row delete and reordering. I also added a detail disclosure set of view controllers.

Now, how do I save the two mutable arrays so the table view is the way it was left? Here is what I am currently trying.

//Saving routine.
NSMutableData *data = [NSMutableData data];
NSMutableData *dataB = [NSMutableData data];
NSKeyedArchiver *encode = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
NSKeyedArchiver *encodeB = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];

NSString* docsPathA = [NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* docsPathB = [NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* filePath = [docsPathA stringByAppendingPathComponent:@"SavedMenuState"];
NSString* filePathB = [docsPathB stringByAppendingPathComponent:@"SavedDetailState"];

[encode encodeObject:menuList forKey:@"SavedMenuList"];
[data writeToFile:filePath atomically:YES];

[encodeB encodeObject:detailList forKey:@"SavedDetailList"];
[dataB writeToFile:filePathB atomically:YES];

[encode finishEncoding];
[encode release];

Then to retrieve upon relaunch.

- (void)awakeFromNib
{
//retrieve saved state
NSString* docsPathA = [NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* docsPathB = [NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* filePath = [docsPathA stringByAppendingPathComponent:@"SavedMenuState"];
NSString* filePathB = [docsPathB stringByAppendingPathComponent:@"SavedDetailState"];

NSFileManager *fileManager = [NSFileManager defaultManager];
if([fileManager fileExistsAtPath:filePath])
{
NSMutableData *data;
NSMutableData *dataB;
NSKeyedUnarchiver *decoder;
NSKeyedUnarchiver *decoderB;

data = [NSData dataWithContentsOfFile:filePath];
decoder = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
self.menuList = [[NSMutableArray alloc] initWithCapacity:13];
self.menuList = [decoder decodeObjectForKey:@"SavedMenuList"];

dataB = [NSData dataWithContentsOfFile:filePathB];
decoderB = [[NSKeyedUnarchiver alloc] initForReadingWithData:dataB];
self.detailList = [[NSMutableArray alloc] initWithCapacity:13];
self.detailList = [decoderB decodeObjectForKey:@"SavedDetailList"];


}
else{
//Main View Selections
self.menuList = [[NSMutableArray alloc] initWithCapacity:13];
//Here is the list of view controllers...

Upon running, the app first works fine, I edit the rows, quit, relaunch, then I just get a blank table view.

What gives?
jmcfizix is offline   Reply With Quote
Old 10-09-2009, 12:52 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 5
Default

Never mind. I just had things out of order. It works now.
jmcfizix is offline   Reply With Quote
Reply

Bookmarks

Tags
decode, encode, nsmutablearray, saving

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: 266
16 members and 250 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, Dani77, DarkAn, HemiMG, iDifferent, jakerocheleau, JasonR, prchn4christ, Rudy, Speed
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
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 02:50 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0