2011-08-24 27 views
0

我在這裏有一個很好的bug,特別是在慢速設備中。 我有一個UITableView,就像App Store應用程序中的一樣,底部有一個Load More按鈕。 當它被按下時,我從服務器加載新的信息,設置數組,並重新加載表格視圖。在那個信息中,也是表格行中顯示的每個對象的圖像的URL,所以當我們得到它時,我們開始重新載入圖像。當圖像加載時,我重新加載對象的行。同時重新加載行和整個表時崩潰

[self.searchResultsTableView reloadRowsAtIndexPaths: [NSArray arrayWithObject: path] withRowAnimation: UITableViewRowAnimationNone]; 

問題是當該行被重新加載,因爲圖像被下載,整個表這樣做會導致用戶按下負載更多按鈕,更多信息被得到。然後我得到這個錯誤:

Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (140) must be equal to the number of rows contained in that section before the update (125), plus or minus the number of rows inserted or deleted from that section (1 inserted, 1 deleted). 

這是完全可以理解的,表被放大,而新的圖像行正在更新。 我的問題是:如何鎖定它,所以我不重新加載該行,直到整個表重新加載?它會很好,像table.isReloading。我嘗試使用布爾鎖,並在主線程中執行這兩個操作,但它不起作用... 非常感謝。

回答

0

好吧,在文檔中的一點研究,在這一切中提供了更多的光。

reloadRowsAtIndexPaths:withRowAnimation: Call this method if you want to alert the user that the value of a cell is changing. If, however, notifying the user is not important—that is, you just want to change the value that a cell is displaying—you can get the cell for a particular row and set its new value.

這就是我做什麼,我得到了細胞,併爲圖像的新的價值,而不是重新加載整個的它。我想這是更有效也:

AHMyTableViewCell *cell = (AHMyTableViewCell *) [self.myTableView cellForRowAtIndexPath:path]; 

       if ((cell != nil) && ([cell isKindOfClass:[AHMyTableViewCell class]])) 
        cell.myImageView.image = image; 

它現在不崩潰。