我们有Like,Dislike和Comment的功能。每当任何用户点击Like按钮更多时间,它就会显示Exc_Bad_Access [Code = 1]错误。下面是代码中我收到此错误的部分。
-(IBAction)sendLike:(id)sender{
UIButton *btn=(UIButton *)sender;
if(!btn.tag)
{
btn.tag=0;
}
postCell *curCell=(postCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:btn.tag inSection:0]];
user *myUser = [[[user alloc] init] autorelease];
if([myUser likeObjectByID:[[[self.thePosts objectAtIndex:[(UIButton *) sender tag]] theData] objectForKey:@"itemID"]]){
curCell.myASB.likeCount += 1;
curCell.myASB.canLike=YES;
[[[self.thePosts objectAtIndex:curCell.myIndex] theData] setObject:[NSString stringWithFormat:@"0"] forKey:@"canLike"];
NSString *tempCount = [NSString stringWithFormat:@"%i", curCell.myASB.likeCount];
[[[self.thePosts objectAtIndex:curCell.myIndex] theData] setObject:tempCount forKey:@"likes"];
[self.tableView reloadData];
}
}
答案 0 :(得分:-3)
尝试在代码中使用try - catch - finally。 也许它会让应用程序继续运行。
@try {
//Here write the code which you want to run,
//In your case add the button action code here.
}
@catch (NSException *exception) {
NSLog(@"Exception At: %s %d %s %s %@", __FILE__, __LINE__, __PRETTY_FUNCTION__, __FUNCTION__,exception);
//Here you can put some alert view to notify the user, that something went wrong.
//This is not compulsary.
}
@finally {
}