2015-09-25 46 views
-1

我們具有「喜歡,不喜歡和評論」功能。每當任何用戶點擊更多的時間點贊按鈕,它就會顯示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]; 
    } 
} 

enter image description here

+0

安置自己在GitHub代碼第一或透露更多的細節,否則就沒有辦法瞭解你的情況 – Ducky

+0

嘗試exclusiveTouch設置爲true – Venkat

+0

嘗試更新項目中使用ARC。 – rmaddy

回答

-3

嘗試使用嘗試 - 抓 - 終於在代碼中。 也許它會讓應用程序繼續運行。

@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 { 
    } 
+1

try/catch不適用於這種例外情況。 – rmaddy