objective c - Reading plist in iOS program -


as i'm beginner ios, want read simple property list file (plist) in program shows me message "terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[viewcontroller datafilepath]: unrecognised selector sent instance 0x15638660'". kindly me out had issue in program.

(.h file) @interface viewcontroller : uiviewcontroller { nsstring *listpath; nsmutablearray *array; }  - (nsstring *) datafilepath; - (void) writeplist; - (void) readplist;  (.m file) @interface viewcontroller ()  @end  @implementation viewcontroller  - (void)viewdidload { uibutton *readbtn = [uibutton buttonwithtype:uibuttontyperoundedrect];        readbtn.frame = cgrectmake(110,110,72,39); [readbtn settitle:@"read" forstate:uicontrolstatenormal]; [readbtn addtarget:self            action:@selector(readplist)forcontrolevents:uicontroleventtouchupinside]; [self.view addsubview:readbtn];  uibutton *writebtn = [uibutton buttonwithtype:uibuttontyperoundedrect]; writebtn.frame = cgrectmake(110,210,72,39); [writebtn settitle:@"write" forstate:uicontrolstatenormal]; [writebtn addtarget:self  action:@selector(writeplist)  forcontrolevents:uicontroleventtouchupinside]; [self.view addsubview:writebtn];      [super viewdidload]; 

}

- (nsstring *)docdirectories { nsarray *path =                    nssearchpathfordirectoriesindomains(nsdocumentdirectory,nsuserdomainmask, yes); nsstring *documentdirectory=[path objectatindex:0]; return  [documentdirectory stringbyappendingstring:@"data.plist"]; 

}

- (void)writeplist { nsmutablearray *anarray = [[nsmutablearray alloc]init];      [anarray addobject:@"a"]; [anarray addobject:@"b"]; [anarray writetofile:[self datafilepath] atomically:yes]; }  - (void)readplist { nsstring *filepath = [self datafilepath]; if ([[nsfilemanager defaultmanager] fileexistsatpath:filepath]) {     nsarray *array = [[nsarray alloc] initwithcontentsoffile:filepath];     nslog(@"%@\n", array);     nslog(@"%@\n",filepath);    // [array release];     } }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  @end } 

you view controller not has method datafilepath.

you need call function docdirectories.

- (void)writeplist {     nsmutablearray *anarray = [[nsmutablearray alloc]init];          [anarray addobject:@"a"];     [anarray addobject:@"b"];     [anarray writetofile:[self docdirectories] atomically:yes]; } 

hope you.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -