//archivingData.m

-(id) initWithCoder:(NSCoder *)aDecoder

{

if (self = [super init]) {


self.email = [aDecoder decodeObjectForKey:@"email"];

self.pwd =[aDecoder decodeObjectForKey:@"pwd"];

}

return self;

}


-(void) encodeWithCoder:(NSCoder *)aCoder

{

[aCoder encodeObject:email forKey:@"email"];

[aCoder encodeObject:pwd forKey:@"pwd"];

}


//viewController.m

- (void)viewDidLoad {

NSString *path = [self DataPath];

if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {

NSMutableData *data = [[NSMutableData alloc] initWithContentsOfFile:path];

NSKeyedUnarchiver *unArchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];

archivingData *archiv = [unArchiver decodeObjectForKey:@"data"];

[unArchiver finishDecoding];

txtEmail.text = archiv.email;

txtPwd.text = archiv.pwd;

[data release];

[unArchiver release];

}

UIApplication *sharedApp = [UIApplication sharedApplication];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:sharedApp];

    [super viewDidLoad];

}



-(void)applicationWillTerminate:(NSNotification *)notif

{

archivingData *archiv = [[archivingData alloc] init];

archiv.email = txtEmail.text;

archiv.pwd = txtPwd.text;

NSMutableData *data = [[NSMutableData alloc] init];

NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];

[archiver encodeObject:archiv forKey:@"data"];

[archiver finishEncoding];

[data writeToFile:[self DataPath] atomically:YES];

[archiv release];

[data release];

[archiver release];

}


-(NSString *)DataPath

{

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *directory = [path objectAtIndex:0];

return [directory stringByAppendingFormat:@"archivingData"];

}

//Document 디렉토리안에 저장되는게 아니라 DocumentsarchivingData 로 저장됨

'Object-C' 카테고리의 다른 글

SQLITE  (0) 2010.10.08
CoreData  (0) 2010.10.07
pickerView  (0) 2010.10.07
imagePicker  (0) 2010.10.07
pageControl  (0) 2010.10.07
-(void)viewDidLoad
{
NSString *path = [[NSBundle mainBundle] pathForREsource:@"data" ofType:@"plist"];

NSDictionary *dic = [[NSDIctionary alloc] initWithContentsOFFile:path];
self.subName = dic;
[dic release];

NSArray *keys = [[self.subName allKeys] sortedArrayUsingSelector:@selector(compare:)];
self.pickerData = keys;

NSString *selectedData = [self.pickerData objectAtIndex:0];
NSArray *array = [self.subName objectForKey:selectedData];
self.subData = array;

}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(component == 0)
{
NSString *selectedData = [self.pickerData objectAtIndex:row];
NSArray *array = [self.subName objectForKey:selectedData];
self.subData = array;

[picker selectRow:0 inComponent:1 animated:YES];
[picker reloadComponent:1];
}
}

'Object-C' 카테고리의 다른 글

CoreData  (0) 2010.10.07
archiving  (0) 2010.10.07
imagePicker  (0) 2010.10.07
pageControl  (0) 2010.10.07
ScrollView  (0) 2010.10.07
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

-(void)btnList:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
imagePicker.delegate = self;

imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

//imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera

[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)selectedImage editingInfo:(NSDictionary *)editingInfo
{
imgView.image = selectedImage;
[self dismissModalViewControllerAnimated:YES];
}

'Object-C' 카테고리의 다른 글

archiving  (0) 2010.10.07
pickerView  (0) 2010.10.07
pageControl  (0) 2010.10.07
ScrollView  (0) 2010.10.07
customCell  (0) 2010.10.07

+ Recent posts