@interfaceViewcontroller ()#defineFileName @ "Student.plist"#defineKname @ "Kname"#defineKbirth @ "Kbirth"#defineKsex @ "Ksex"#defineKnumber @ "Knumber"#defineKhome @ "Khome"@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.[[Nsnotificationcenter defaultcenter] addobserver:self selector: @selector (keyboardwillshow) Name:uikeyboardwil LshownotificationObject: nil]; [[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (keyboardwillhide) Name: UikeyboardwillhidenotificationObject: nil]; Nsdictionary*dictionary=[Nsdictionary dictionarywithcontentsoffile:[self FilePath]; if(dictionary) {Self.nameField.text=[dictionary objectforkey:kname]; }} - (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}-(Ibaction) Save: (ID) Sender { Do{nsstring*name=[Self.namefield text]; NSString*bith=[Self.birthfield text]; Nsinteger Sex=[Self.sexseg Selectedsegmentindex]; NSString*home=[Self.homefield text]; NSString*number=[Self.numberfield text]; if(!name| |! bith| |! home| |!Number ) { Break; } nsmutabledictionary*dic=[Nsmutabledictionary dictionary]; [DiC Setobject:name Forkey:kname]; [DiC Setobject:bith Forkey:kbirth]; [dic Setobject:[nsnumber Numberwithinteger:sex] forkey:ksex]; [DiC Setobject:number Forkey:knumber]; [DiC Setobject:home Forkey:khome]; if([dic writetofile:[self FilePath] atomically:yes]) {Uialertview*alertview=[[uialertview Alloc]initwithtitle:@"Save success! "Message:nilDelegate: Nil Cancelbuttontitle:@"Determine"Otherbuttontitles:nil, nil]; [Alertview show]; } return; } while(0); Uialertview*alertview=[[uialertview Alloc]initwithtitle:@"Warning"Message@"basic information cannot be empty" Delegate: Nil Cancelbuttontitle:@"Determine"Otherbuttontitles:nil, nil]; [Alertview show];}//return to Sandbox path-(NSString *) filepath{Nsarray*array=nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES); NSString*path= [[Array Objectatindex:0] Stringbyappendingpathcomponent:filename]; returnpath;}- (void) Touchesbegan: (Nsset *) touches withevent: (Uievent *)Event{[Self.namefield resignfirstresponder]; [Self.birthfield Resignfirstresponder]; [Self.numberfield Resignfirstresponder]; [Self.homefield Resignfirstresponder];}- (void) keyboardwillshow{[UIView beginanimations:@"Show"Context:nil]; [UIView Setanimationcurve:uiviewanimationcurveeaseinout]; CGRect rect=Self.view.frame; RECT.ORIGIN.Y=- +; Self.view.frame=rect; [UIView commitanimations];}- (void) keyboardwillhide{[UIView beginanimations:@"Hide"Context:nil]; [UIView Setanimationcurve:uiviewanimationcurveeaseinout]; CGRect rect=Self.view.frame; RECT.ORIGIN.Y=0; Self.view.frame=rect; [UIView commitanimations];}View Code
Serialization and deserialization (Nsdictionary), listening keyboard