iOS错误: Thread 1:EXC_BAD_ACCESS(code=1,地址=0x726f635f)?

标签 ios objective-c multithreading exc-bad-access

我在开发第一个管理数据库的 iOS 应用程序时遇到了这个问题。 我有一个包含游戏分数的数据库,并希望将它们显示在表格中,当(在运行时)我输入 ScoreView 应用程序崩溃并出现以下错误时:

Thread 1:EXC_BAD_ACCESS(code=1,address=0x726f635f)

下面是 Xcode 向我显示的导致此问题的代码:

    if (sqlite3_prepare_v2(database, sql , -1, &select_statement, NULL)
    == SQLITE_OK) {
                    while (sqlite3_step(select_statement) == SQLITE_ROW){
                        // read from DB
                        NSString *rank = [NSString stringWithUTF8String:(char *)sqlite3_column_text(select_statement, 0)];
                        NSString *name = [NSString stringWithUTF8String:(char *)sqlite3_column_text(select_statement, 1)];
                        NSString *score = [NSString stringWithUTF8String:(char *)sqlite3_column_text(select_statement, 2)];
                        NSString *date = [NSString stringWithUTF8String:(char *)sqlite3_column_text(select_statement, 3)];

                        // I insert all the string in a dictionary
                        NSDictionary *dictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:rank,@"Rank",name,@"Name",score,"Score",date,@"Date",nil];
                        [tempList addObject:dictionary];
                    }

                self.list = tempList;
                sqlite3_finalize(select_statement);
}

错误所在行:

NSDictionary *dictionary = [[NSMutableDictionary alloc] initWithObjectsAndKeys:rank,@"Rank",name,@"Name",score,"Score",date,@"Date",nil];

从数据库读取后,我尝试将所有字符串保存在字典中,最后所有字典(在 tempList 中)都进入“列表”,这是一个在表中显示分数的数组。 我在网上看到这个问题可能是由不同的线程访问同一对象引起的,但我不知道如何解决。 我正在遵循在 iOS 应用程序中使用 DB 的教程,当然这个问题不存在。 如果有人可以帮助我,我将非常感激,谢谢。

最佳答案

您有一个语法错误:

... score, "Score" ...

应阅读:

... score, @"Score" ...

关于iOS错误: Thread 1:EXC_BAD_ACCESS(code=1,地址=0x726f635f)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24467198/

相关文章:

objective-c - objective-C 和 objective-C++ 中静态成员的定义

objective-c - Objective C - 后台执行选择器并且分离新线程选择器?

ruby-on-rails - 这是 Rails 验证线程安全的吗

ios - 无法在扩展 Objective - C 类的 Swift 类中访问私有(private)变量

multithreading - 如何同时加载/更新JSF/PrimeFaces组件? [复制]

java - 线程: Shared Resource special situation

ios - UIImageView 在下一个 ViewController 打开时与 UILabel 重叠

ios - 如何在iOS swift中隐藏/查看标题 View 表

ios - 将数据从 UITableViewCell 推送到 ViewController

ios - Amazon AWSS3TransferManager 在 ios 中无法上传多部分数据