2011-09-02 58 views
1

將項目列表加載到UITableview並能夠單擊並顯示所選行的警報。但是,在提示「ok」後,我重新點擊已經選擇的行,我的代碼就會出現「Thread 1:Program received signal:EXC_BAD_ACCESS」。請看下面的代碼。UITableView didSelectRowAtIndexPath錯誤 - 再次選擇項目時

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSDictionary *playerselected = [exercises objectAtIndex:indexPath.row]; 
    NSString *video = [playerselected valueForKey:@"video"]; 

    NSString *msg = [[NSString alloc] initWithFormat:@"You have selected %@", video]; 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Player selected" 
                message:msg 
                delegate:self 
              cancelButtonTitle:@"OK" 
              otherButtonTitles:nil];  

    [alert show];  
    [alert release]; 
    [video release]; 
    [msg release]; 

} 

請教我這裏有什麼問題。

+0

好的,我看了一下。你有什麼特別的問題嗎?只是在開玩笑,儘管如果你提出一個具體的問題,它會有所幫助,並儘可能詳細地解釋你的問題(例如錯誤發生在哪一行)。只需簡單地傾銷代碼就不會成爲其他人提供幫助的良好動機。 – Mac

+0

Sry MAc糾正了上述問題。 – UnlimitedMeals

回答

2

請勿發佈video

當您從NSDictionary檢索值時,您不擁有它,除非您明確地retain它。

更具體地說,當你檢索你的字符串時,它仍然屬於字典。當你release它,你正在釋放一個你不擁有的對象,導致它被過度釋放。因此它被釋放,當你下次嘗試訪問它時,內存不再有效,你的應用程序崩潰。

+0

Thx Mac。我意識到我在做什麼。這工作。 – UnlimitedMeals

相關問題