我在将值数组插入表时遇到问题。我必须将联系人详细信息数组插入表中。也就是说,我有一个变量中的名字列表,姓氏列表一个变量等..同样我要插入 24 列..
它抛出一个异常说:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[contactlist filepath]: unrecognized selector sent to 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 an exception
谁能帮我解决这个问题..?
- (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 INTO 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"];
}