Serialization and deserialization (Nsdictionary), listening keyboard

Source: Internet
Author: User

@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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.