2013-04-25 59 views
0

我得到這個錯誤:請幫助爲什麼我的應用程序崩潰,出現以下錯誤:?

[NSIndexPath row]: message sent to deallocated instance 0x13135d50

我的代碼:

-(void) scrollViewDidFinishScrolling: (UIScrollView*) scrollView { 
    CGPoint point = [self convertPoint:CGPointMake(self.frame.size.width/2.0, kDefaultCellHeight/2.0) toView:self.tableView]; 
    NSIndexPath* centerIndexPath = [self.tableView indexPathForRowAtPoint:point]; 

    [self.tableView selectRowAtIndexPath: centerIndexPath 
          animated: YES 
         scrollPosition: UITableViewScrollPositionTop]; 

    if (centerIndexPath.row != self.currentIndex.row) { 
     //Hide the arrow when scrolling 
     [self setCurrentIndex:centerIndexPath]; 
    } 

    [self.arrow show:YES]; 
+1

'self.currentIndex'必須被釋放,你如何聲明/創建它? – 2013-04-25 21:11:35

+0

您可以在調試器中重複該問題嗎? – 2013-04-25 21:12:14

+0

消息說明。您在不再指向有效對象的指針上調用「行」。據推測問題指針是currentIndex,可能的原因是它沒有妥善保留。但是你需要運行分析儀並進行一些調試來確定它。 – 2013-04-25 21:12:25

回答

0

你引用解分配變量,則NSIndexPathself.currentRow。代碼中的某處(其他地方)您正在獲得對其的引用,但未保留它 - 如果這樣做,則不應再看到此錯誤。只需確保在不再需要時釋放它。

+0

它似乎可能是'self.currentIndex'的問題。 – 2013-04-25 21:16:26

+0

@BrianNickel是的,我已經更新了我的回答。謝謝。 – Madbreaks 2013-04-25 21:16:53

+1

如果使用ARC,則應該強烈保留centerIndexPath,所以它很可能是self.currentIndex,這可能是一個弱引用。 – Skotch 2013-04-25 21:19:54

0

如果不使用ARC,確保currentIndex是一個保留屬性(如果使用ARC,則爲strong)。由於indexPathForRowAtPoint:返回一個自動釋放對象,因此如果要將它保留在別處使用,則需要保留它。

相關問題