【发布时间】:2011-11-02 08:30:29
【问题描述】:
我已经实现了这段代码,当我尝试添加对象时它工作正常,但是当我尝试删除对象时它给了我 exc_bad_access,我尝试通过放置断点来找出原因,但我仍然无法得到原因。请帮帮我。
在 .h 文件中
BOOL prayValues[1000];
BOOL praiseValues[1000];
IBOutlet UITableView *prayTable;
IBOutlet UITableView *praiseTable;
NSMutableArray *publishingMyPosts;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(@"sterrrr----%@",str);
if (tableView == myTableView) {
NSLog(@"did select in tableview");
}
if (jsonRequestChecking==2) {
UITableViewCell *thisCell1 = [prayTable cellForRowAtIndexPath:indexPath];
UITableViewCell *thisCell2 = [praiseTable cellForRowAtIndexPath:indexPath];
if (tableView == prayTable) {
NSLog(@"did select in prayTable");
prayValues[indexPath.row] = !prayValues[indexPath.row];
if (prayValues[indexPath.row]) {
thisCell1.accessoryType = UITableViewCellAccessoryCheckmark;
NSLog(@"this cell1 text %@",thisCell1.textLabel.text);
str=[NSString stringWithFormat:@"%@",[[publicArray objectAtIndex:indexPath.row] objectForKey:@"id"]];
if (([publishingMyPosts containsObject:str] == NO)){
[publishingMyPosts addObject:str];
// NSLog(@"publishing my post %@",publishingMyPosts);
}
} else {
thisCell1.accessoryType = UITableViewCellAccessoryNone;
[publishingMyPosts removeObject:str];
//NSLog(@"publishing my post %@",publishingMyPosts);
}
}
if (tableView == praiseTable) {
NSLog(@"did select in praiseTable");
praiseValues[indexPath.row] = !praiseValues[indexPath.row];
if (praiseValues[indexPath.row]) {
str1=[NSString stringWithFormat:@"%@",[[privateArray objectAtIndex:indexPath.row] objectForKey:@"id"]];
thisCell2.accessoryType = UITableViewCellAccessoryCheckmark;
NSLog(@"this cell2 text %@",thisCell2.textLabel.text);
if (([publishingMyPosts containsObject:str1] == NO)){
[publishingMyPosts addObject:str1];
// NSLog(@"publishing my post %@",publishingMyPosts);
}
} else {
thisCell2.accessoryType = UITableViewCellAccessoryNone;
[publishingMyPosts removeObject:str1];
//NSLog(@"publishing my post %@",publishingMyPosts);
}
}
}
NSLog(@"publishing my post %@",publishingMyPosts);
}
【问题讨论】:
-
认为这一定与您的 str 在调用之间被自动释放有关吗?还在看。
-
你确定你的应用程序由于从数组中删除了 obj 而崩溃了吗???
-
是的。我敢肯定,当我尝试删除对象时,它给了我非常糟糕的访问权限,并且它随机有时会删除 3 个对象,然后在删除 2 个对象时给我非常糟糕的访问权限和一些时间
-
NSString * str; NSString * str1;在具有非原子属性的 .h 文件中声明并保留和即时释放它。
-
您在代码中使用的是
[str release]还是[str1 release]`????
标签: iphone ios xcode uitableview nsmutablearray