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 01-05-2012, 11:59 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2012
Posts: 2
avarahala is on a distinguished road
Default Saving state of Image View between views

Hi All,

Here is my scenario, The user transitions from one image view to the
other. After performing some actions on the second image view, he may
want to go back to the first one. He presses the back button
(LeftBarButtonItem) and then when he returns to the second view, I
want him to have the same state at which he left off. my second view is an array of imageViews.

This is how I am trying to implement this

-(void) retrieveFromUserDefaults
{
NSUserDefaults * standardDefaults = [NSUserDefaults standardUserDefaults];
NSData * tempObject = [ standardDefaults objectForKey:@"myKeyToSave" ];
NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithData:tempObject];

myImageViewArr = [NSMutableArray arrayWithArray:arr];
}

-(void)saveToUserDefaults
{
NSUserDefaults * standardDefaults = [NSUserDefaults standardUserDefaults];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:myImageViewArr];
[standardDefaults setObject:data forKey:@"myKeyToSave"];

}


- (id) initWithCoder: (NSCoder *)decoder
{
myImageViewArr = [decoder decodeObjectForKey:keyToSave];
return myImageViewArr;
}

- (void) encodeWithCoder: (NSCoder *)encoder
{
[encoder encodeObject:myImageViewArr forKey:keyToSave];
}


- (void)viewWillDisappearBOOL)animated {
[self saveToUserDefaults];
}


My App just seems to crash. Can anyone point me in the right direction as what I am doing wrong?

Thanks
Ajit
avarahala is offline   Reply With Quote
Reply

Bookmarks

Tags
avarahala, nsuserdefaults

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: 402
12 members and 390 guests
buggen, EvilElf, guusleijsten, j.b.rajesh@gmail.com, LunarMoon, morterbaher, QuantumDoja, sacha1996, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

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