2012-08-31 68 views
4

我想在UITableview中加載大約6000-8000行。我從使用異步調用服務器獲取數據,當我得到的數據我打電話dequeueReusableCellWithIdentifier不起作用

 
[tableView reloadData] 

這是刷新表視圖。但由於某種原因,我的應用程序被卡住並凍結。 當我調試時,我發現cellforrowatindexpath被稱爲6000次(在主線程上),並且 dequeueReusableCellWithIdentifier總是返回null。

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
     CDTableRowCell *cell = nil; 

     // Create and Resue Custom ViewCell 
     static NSString *CellIdentifier = @"CellIdentifier"; 
     cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

     // got into render/theme objec 
     if(cell == nil){ 
      cell = [[CDTableRowCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
     } 

// MODIFYING CELL PROPERTIES HERE FROM AN ARRAY 
// NO HTTP CALLS 

} 

此外,tableview開始重新使用單元格,一旦我開始滾動,但在此之前,我永遠不會總是創建一個新的。 任何線索爲什麼這種奇怪的行爲?

+0

你有沒有機會告訴tableview每行的高度爲0?如果它認爲所有單元格都應該可見,則可以解釋此行爲。 –

+0

@KevinBallard讓我檢查 –

+0

@KevinBallard 我試過,但似乎並不工作 - (CGFloat的)的tableView:(UITableView的*)的tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 回報40; } –

回答

0

嘗試這樣,

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier [email protected]"Cell"; 

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 

     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

} 

return cell; 

} 
+0

我做過了,仍然有同樣的問題。 –

+0

我認爲你在編碼的其他地方有問題... – Venkat

+0

我不這麼認爲,因爲當我在這個函數中使用NSLog語句時。我看到這被多次調用,而且這個函數阻止了我的主線程。 –

0

你的問題的方法是不是表視圖數據源的方法。數據源方法具有表視圖作爲參數。你寫的方法可以用來從tableView本身獲得一個單元格,而不是從數據源獲得一個新的單元格。

我不知道該方法被調用的頻率如何,但覆蓋它幾乎肯定不是您想要做的。

我猜你已經將一個uitableview子類化爲自己的數據源?如果是這樣,您需要在數據源方法tableView:cellForRowAtIndexPath:中的問題中包含代碼,而不是像現在那樣覆蓋該方法。

+0

是正確的 - 您還應該考慮使用NSFetchedResultsController來管理數據,而不是處理6000行 - 雖然複雜,但NSFetchedResultsController是一種非常聰明的方式,可以在您的應用程序中獲得一些響應。 – ferdil

+0

謝謝 - 你是對的 - 發佈後我意識到這一點,但無法弄清楚如何移動我的「評論」 – ferdil

相關問題