该方法在玩纸牌游戏之前有效 n 次,之后第一次失败

method works n times before playing card game, fails first time afterwards

我真的不知道如何给这个问题起标题,所以我提前道歉....

构建闪存卡应用程序。可以通过对 include/exclude 某些大陆的偏好来过滤纸牌。我将过滤器设置为仅包括一个大陆,然后我成功玩了游戏。完成甲板后,我决定包括第二个大陆。失败。

我正在使用 TableViewController 来显示六大洲。原型单元格是 "Right detail"。 textLabel.text 是大陆名称。 detailText.text 显示 inclusion/exclusion 状态。

所有大陆都以 "include" 开头。单击一行,它会切换 on/off.

我可以在屏幕上进行更改,保存设置,然后返回并进行更多更改而不会崩溃。应用程序 在检查一副牌后崩溃,无论是 10 张还是 100 张。

错误信息:-[__NSArrayI addObject:]: unrecognized selector sent to instance

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString *name = cell.textLabel.text;
if ([[GameSettingsObject sharedInstance].chosenContinents containsObject:name]) {
    if ([[GameSettingsObject sharedInstance].chosenContinents count]>1) {
        [[GameSettingsObject sharedInstance].chosenContinents removeObject:name];
        cell.detailTextLabel.text = @"exclude";
    }
} else {
    [[GameSettingsObject sharedInstance].chosenContinents addObject:name];
    cell.detailTextLabel.text = @"include";
}

}

有什么想法吗?

您只能将对象添加到可变数组中。所以我认为你的数组以某种方式变成了 NSArray。检查一下。