我已經實現了這個代碼,當我嘗試添加它正常工作的對象,但是當我嘗試刪除對象時,它給我EXC_BAD_ACCESS,我試圖通過把破發點,但還是以找出消除我無法得到這個原因。請幫幫我。iphonesdk值從arrray給出EXC壞訪問
在.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);
}
認爲它必須與通話之間自動釋放你的海峽辦?仍在通過它看。 – wmorrison365
你確定你的應用程序崩潰了,因爲從數組中刪除了obj? –
yap。我敢肯定,它給了我不好的訪問時,當我嘗試刪除對象,它的隨機一些時間它刪除3個對象,然後給我不好的訪問和一些時間,同時刪除2對象 –