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