Data Persistence basics-List of attributes

Source: Internet
Author: User
Tags list of attributes

Property list:

1 //Insert 4 text boxes2@property (Strong, Nonatomic) iboutletcollection (Uitextfield) Nsarray *Linefields;3 4 5 //gets the path, checks whether the data file exists, and appears in the text box. 6- (void) Viewdidload {7 [Super Viewdidload];8NSString * FilePath =[self datafilepath];9     if([[[Nsfilemanager Defaultmanager] Fileexistsatpath:filepath]) {TenNsarray * Array =[[Nsarray alloc] initwithcontentsoffile:filepath]; One          for(inti =0; I <4; i++) { AUitextfield * Thefield =Self.linefields[i]; -Thefield.text =Array[i]; -         } the     } -  - //Save the data before terminating the operation or entering the background.  -UIApplication * App =[UIApplication sharedapplication]; +[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (applicationwillresignactive:) Name: UiapplicationwillresignactivenotificationObject: app]; - } +  A //gets the file path and returns.  at-(NSString *) DataFilePath - { -Nsarray * paths =nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES); -NSString * documentsdirectory = [Paths Objectatindex:0]; -     return[Documentsdirectory stringbyappendingpathcomponent:@"data.plist"]; - } in  - //the method to execute before terminating or entering the background.  to- (void) Applicationwillresignactive: (Nsnotification *) Notification + { -NSString * FilePath =[self datafilepath]; the      *      //construct an array of strings by calling the text method of each textbox in the Linefields array, calling the Valueforkey: method, and passing the @ "text" as the parameter, which implements iterating to get the text value of the instance variable.  $Nsarray * array = [Self.linefields Valueforkey:@"text"];Panax Notoginseng [Array Writetofile:filepath atomically:yes]; -}
View Code

Data Persistence basics-List of attributes

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.