ios - Inserting array of values into a table -
i've issue in inserting array of values table.. i've insert array of contact details table.. is, i've list of first names in variable, list of last names in variable, etc.. likewise i've 24 columns inserted..
it throws exception saying:
*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[contactlist filepath]: unrecognized selector sent instance 0xa2af5b0' *** first throw call stack: (0x257e012 0x1e06e7e 0x26094bd 0x256dbbc 0x256d94e 0x4b613 0x4b551 0x190c589 0x190a652 0x190b89a 0x190a60d 0x190a785 0x1857a68 0x4a0911 0x49fbb3 0x4ddcda 0x25208fd 0x4de35c 0x4de2d5 0x3c8250 0x2501f3f 0x250196f 0x2524734 0x2523f44 0x2523e1b 0x2ad57e3 0x2ad5668 0xd4affc 0x254d 0x2475) libc++abi.dylib: terminate called throwing exception
can me out on this..?
- (void)connectiondidfinishloading:(nsurlconnection *)connection { nserror *error; json = [nsjsonserialization jsonobjectwithdata:responsedata options:kniloptions error:&error]; nslog(@"json.... %@",json); id jsonobject = [nsjsonserialization jsonobjectwithdata:responsedata options:nsjsonreadingallowfragments error:nil]; nslog(@"jsonobject=%@", jsonobject); nsarray *checkarray=[jsonobject valueforkey:@"nd"]; chedisk=[checkarray valueforkey:@"fn"]; chedisk1=[checkarray valueforkey:@"ln"]; nslog(@"fn =%@",chedisk); nslog(@"ln =%@",chedisk1); fname = [nsstring stringwithformat:@"%@",[chedisk objectatindex:0]]; lname = [nsstring stringwithformat:@"%@",[chedisk1 objectatindex:0]]; [self insertdata]; [contacttableview reloaddata]; } -(void)insertdata { if (sqlite3_open([[self filepath]utf8string], &db) == sqlite_ok) { nsstring *insertstatement = [nsstring stringwithformat:@"insert pu_contacts (firstname, lastname) values ('%@', '%@')", fname, lname]; char *error; sqlite3_exec(db, [insertstatement utf8string], null, null, &error)!= sqlite_ok; sqlite3_close(db); } } +(nsstring *) filepath { nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdir = [paths objectatindex:0]; return [documentsdir stringbyappendingpathcomponent:@"uwdatabase1.sql"]; }
issue code:
[self filepath]
you defined method class method
, can't call using self
.
+(nsstring *) filepath
solution 1:
change call [contactlist filepath];
using class name.
solution 2:
change method instance method, like:
- (nsstring *) filepath { nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdir = [paths objectatindex:0]; return [documentsdir stringbyappendingpathcomponent:@"uwdatabase1.sql"]; }
Comments
Post a Comment