2013-12-10 45 views
1

有沒有人有任何經驗使用tableView內的一個collectionViewCell?CollectionViewCell裏面的TableView

我有一個tableView裏面的一個collectionViewCell(每個是全屏視圖)。每個collectionViewCell都顯示其自己的唯一數據。您可以在每個collectionViewCell之間水平滾動。 tableview有一個帶有幾個標籤的自定義tableviewCell。我正在使用tableview來利用內置的tableview重新排序功能。

第一個collectionViewCell加載正常,數據正確顯示在tableview中。但是,當我滾動collectionView單元格時,tableView爲空(僅顯示標籤中的佔位符文本),直到collectionViewCell停止滾動,然後突然顯示正確的數據。

有關如何確保tableview在顯示前已經填充了正確數據的任何建議?我需要它已經在那裏,因爲用戶拖動下一個collectionViewCell(就像背景圖像/標題文本已經存在)。

Here's a link to my project so you can see the code.

任何幫助表示讚賞!

回答

1

我還沒有經歷過這樣做。

但我認爲您可以減少創建對您的單元格的引用的問題。所以你的手機不會被釋放。你可以使用一個數組來做到這一點。

編輯:

你的問題是,你正在使用的定時器,以更新TableViewCell

您的標籤,您可以更改此:

if (!timer) { 
     timer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(updateLabels:) userInfo:nil repeats:YES]; 
    } 

此:

[self updateLabels:nil]; 

並更改您的updateLabels:爲:

- (void)updateLabels:(NSTimer *)_timer 
{ 
    if (!timer) { 
     timer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(updateLabels:) userInfo:nil repeats:YES]; 
    } 

    unitOfTimeLabel.text = nameOfTimeLabel; 

    if ([nameOfTimeLabel isEqualToString:@"Days"]) amountOfTimeLabel.text = [self daysRemaining]; 
    if ([nameOfTimeLabel isEqualToString:@"Hours"]) amountOfTimeLabel.text = [self hoursRemaining]; 
    if ([nameOfTimeLabel isEqualToString:@"Minutes"]) amountOfTimeLabel.text = [self minutesRemaining]; 
    if ([nameOfTimeLabel isEqualToString:@"Seconds"]) amountOfTimeLabel.text = [self secondsRemaining]; 
} 
+0

你指的是collectionViewCell或tableviewCell嗎?我需要重用collectionViewCells,因爲可能有很多它們,如果可能的話,不想將它們保存在內存中。 – Tim

+0

我指的是collectionViewCell。但是,如果你將有很多人,你需要尋找另一種方法,也許有一個負載指標。我不知道如何在收集之前等待'reloadTable' ... – dcorbatta

+0

@Tim看看我編輯的答案 – dcorbatta

1

在collectionviewcontroller中將此方法替換爲this。在這裏我們可以動態設置值細胞

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    tableViewTimeDisplayCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

    if (cell == nil) { 

     NSArray *arrayCellXib = [[NSBundle mainBundle] loadNibNamed:@"tableViewTimeDisplayCell" 
                   owner:self 
                  options:nil]; 

     cell = arrayCellXib[0];//[arrayCellXib objectAtIndex:0]; 
     [cell setNameOfTimeLabel:cellOrderArray[indexPath.row]];//[cellOrderArray objectAtIndex:1] here we can make it as dynamic index 
     [cell setEventNumber:eventNumber]; 
     [cell startTimer]; 
    } 

    return cell; 
} 

//我猜問題是,當我們滾動水平泰伯維再次,也分配集合視圖。在集合視圖中,我刪除了重新加載tableview並粘貼到initwithframe中的代碼。每當這種情況發生時,視圖就會分配。

+0

嘿,謝謝你。當然更整潔的代碼。你能否解釋一下你在initwithframe中粘貼重新加載tableview的最後一條陳述。是的,每次tableview分配都會讓內存吃光。需要解決這個問題。 – Tim

相關問題