-(Void) loadview
{
Uiview * aview = [[uiview alloc] initwithframe: cgrectmake (0, 0,320,480)];
Aview. backgroundcolor = [uicolor whitecolor];
Self. view = aview;
[Aview release];
T1 = [[uitextfield alloc] initwithframe: cgrectmake (80, 30, 80, 30)];
T1.borderstyle = uitextborderstyleroundedrect;
T1.text = @"";
[Aview addsubview: T1];
T2 = [[uitextfield alloc] initwithframe: cgrectmake (80,120, 80, 30)];
T2.borderstyle = uitextborderstyleroundedrect;
T2.text = @"";
[Aview addsubview: T2];
T3 = [[uitextfield alloc] initwithframe: cgrectmake (80,210, 80, 30)];
T3.borderstyle = uitextborderstyleroundedrect;
T3.text = @"";
[Aview addsubview: T3];
Nsfilemanager * fm = [nsfilemanager defamanager manager];
If ([FM fileexistsatpath: [self filepath]) //If any file exists, it is retrieved from the file.,Read from File
{
Nsarray * arr = [nsarray arraywithcontentsoffile: [self filepath];
T1.text = [arr objectatindex: 0];
T2.text = [arr objectatindex: 1];
T3.text = [arr objectatindex: 2];
}
Nslog (@ "% @", [self filepath]);
//Background running
[[Nsicationcenter center defacenter center] addobserver: Self selector: @ selector (savedata) Name: uiapplicationdidenterbackgroundnotification object: Nil];
}
-(Void) savedata
{
Nsarray * Texts = [nsarray arraywithobjects: t1.text, t2.text, t3.text, nil];
[Texts writetofile: [self filepath] atomically: Yes]; //Store data in a file
}
-(Nsstring *) filepath
{
// DocumentPath
Nsstring * docpath = [nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes) objectatindex: 0];
Nsstring * Path = [docpath stringbyappendingpathcomponent: @ "texs"];
ReturnPath;
}