2015-02-09 36 views
5

上下文: 我使用AsyncDisplayKit加載包含文本和圖像的表格。圖像從互聯網下載,圖像尺寸未知,直到圖像完成下載。使用ASNetworkImageNode下載圖像後,從AsyncDisplayKit重新佈局ASTableView

我想要做的事:圖像下載完成 後,我想重新大小和佈局單元格,以適應圖像,然後重新大小和佈局,以適應表新的細胞高度。

什麼我迄今所做的: 我最初只是文本繪製ASTableView並使用ASNetworkingImage委託方法,imageNode:didLoadImage方法當圖像下載完成時獲取通知。

- (void)imageNode:(ASNetworkImageNode *)imageNode didLoadImage:(UIImage *)image { 

    // Scale image downloaded from Internet to fit constrained width 
    // Set networkImageNode to scaled image 
    UIImage *newimage = [self scaleImage:image toConstrainedWidth:CONSTRAINED_WIDTH]; 
    self.networkImageNode.image = newimage; 

    // Gets the parent cell 
    // Recalculate cell size and layout the cell (This works!) 
    MyAsyncTableCellNode *parentCell = ASDisplayNodeFindClass(self, [MyAsyncTableCellNode class]); 
    [parentCell invalidateCalculatedSize]; 
    [parentCell measure:CGSizeMake(CONSTRAINED_WIDTH, MAXFLOAT)]; 
    [parentCell layout]; 

    // Attempting to re-layout the table to shift the table cells 
    // to accommodate for the new cell height (ALL these do NOT work!) 
    MyAsyncTableViewController *parentTableViewController = ASDisplayNodeFindClass(self, [MyAsyncTableViewController class]); 
    // Attempt #1 
    [parentTableViewController.asyncTableView reloadData]; 

    // Attempt #2 
    [parentTableViewController.asyncTableView beginUpdates]; 
    [parentTableViewController.asyncTableView endUpdates]; 
} 

我能夠成功地重新計算單個細胞和重新佈局的大小和繪製單元格,以適應下載的圖像。

問題: 然而,接下來,我需要重新佈局表到其他細胞轉移向下或向上,以適應更新的單元格的新的大小。 這是我無法工作的事情。

嘗試#1將重新計算表的子視圖並重新佈局,但也會重新加載所有數據,這不是我想要的。我想重新計算並重新佈局單元格,而不是重新加載所有數據。

嘗試#2:當使用UITableView時,這樣做將調用tableView:heightForRowAtIndexPath並重新佈局所有表格單元格,但不幸的是,對於ASTableView,這會引發一個未實現的異常。

問題: 如何以編程方式使ASTableView重新佈局本身並考慮新的單元高度?

回答

0

你的第一次嘗試應該是正確的,因爲這再次調用numberOfSectionsInTableView,numberOfSectionsInTableView,nodeForRowAtIndexPath方法,並且不應該重新加載數據源,除非你指定了這樣的值(作爲常規的UITableView)。