2011-01-20 108 views
0

我正在使用UITableView多重选择和sqlite3。 通过下面的代码,我可以显示多个选择,但是对数据库的保存机制有问题。UITableView多重选择

updatedID是一个NSInteger。

当调试消息是如下面,就在--->self.updatedID = ct.contactID;

程序接收到的信号:“EXC_BAD_ACCESS”。

我的代码在这里出了什么问题?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

UITableViewCell *theCell = [tableView cellForRowAtIndexPath:indexPath]; 
MyContacts *ct = (MyContacts *) [self.memberNoGroupArray objectAtIndex:indexPath.row]; 

self.updatedID = ct.contactID; 

if (theCell.accessoryType == UITableViewCellAccessoryCheckmark) 
{ 

    DBAccess *updateDB = [[DBAccess alloc] init]; 
    [updateDB updateGroupName:updatedID withGroupName:[NSString stringWithFormat:@"(no group)"]]; 
    [updateDB release]; 

    theCell.accessoryType = UITableViewCellAccessoryNone; 


} 

//if the cell doesn't have checkmark, give it a checkmark. 
else if (theCell.accessoryType == UITableViewCellAccessoryNone) 
{ 

    DBAccess *updateDB = [[DBAccess alloc] init]; 
    [updateDB updateGroupName:updatedID withGroupName:self.currentGroupString]; 
    [updateDB release]; 

    theCell.accessoryType = UITableViewCellAccessoryCheckmark; 
} 

[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

} 

非常感谢!

回答

0

使用NSZombiesEnabled来查找问题的原因,并在调试器中查看它们。

转到XCode - > Projects - >编辑活动可执行文件“YourProjectName” - > Arguments选项卡 - >转到'要在环境中设置变量' - >添加变量“NSZombiesEnabled”并将其值设置为“YES”也不要忘记检查复选标记。

然后调试代码,并在崩溃时在调试器中看到这个错误的原因是什么。

0

我在调试器中得到这个消息:

GDB:程序接收到的信号: “SIGABRT”。

,有时这样的:

GDB:程序接收到的信号: “EXC_BAD_ACCESS”。

消息似乎不同之间这两个我每次调试。这是我第一次使用NSZombiesEnabled。你看到有什么不对吗?