Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 另一个EXC\u坏访问_Objective C_Xcode_Ipad_Ios - Fatal编程技术网

Objective c 另一个EXC\u坏访问

Objective c 另一个EXC\u坏访问,objective-c,xcode,ipad,ios,Objective C,Xcode,Ipad,Ios,我修复了上一个问题的错误,但我的代码引发了另一个EXC\u BAD\u访问 在 完整的代码是 sqlite3 *database; // Setup some globals NSString *databaseName = @"test.sql"; // Get the path to the documents directory and append the databaseName NSArray *documentPaths = NSSearchPathForDirectoriesI

我修复了上一个问题的错误,但我的代码引发了另一个EXC\u BAD\u访问

完整的代码是

sqlite3 *database;
// Setup some globals
NSString *databaseName = @"test.sql";

// Get the path to the documents directory and append the databaseName
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString * databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
[databasePath retain];
sqlite3_stmt *compiledStatement;

NSString * TheNewText = self.animalDesciption.text; 
[TheNewText retain];

NSString * the_user = AnimalName ;
[ the_user retain];

NSString *NewData = [NSString stringWithFormat:@"%@%@%@%@", @"Update animals set description = ",TheNewText , " Where name =  ",the_user];

[NewData retain] ;

if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {

    const char *sqlStatement = [NewData UTF8String];



    if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL)== SQLITE_OK) {

        sqlite3_reset(sqlStatement);
    }

我敢打赌字符串是通过自动释放运行收集的。在文档中查找UTF8String,他们建议复制该字符串以确保其持续时间超过该点

经过深思熟虑后,我真正的建议是去掉对垫脚石变量的赋值

我想说,像这样使用它:

if(sqlite3_prepare_v2(database, [NewData UTF8String], -1, &compiledStatement, NULL)== SQLITE_OK) {

        sqlite3_reset(compiledStatement);

注意重置语句中的更改。这可能是您真正的问题,您的代码试图执行一个字符串而不是一个准备好的sqlite语句。

您是否尝试过alloc和init NSString

NSString *NewData = [[NSString alloc] initWithFormat:@"%@%@%@%@", @"Update animals set description = ",TheNewText , " Where name =  ",the_user];

不要留着吗?

请给我更多的插图好吗
NSString *NewData = [[NSString alloc] initWithFormat:@"%@%@%@%@", @"Update animals set description = ",TheNewText , " Where name =  ",the_user];