2013-11-01 30 views
2

我拼命試圖達到以下效果:我有一個tableview,我想擴大選擇單元格並顯示一些其他信息。我重複使用表格單元格,僅供參考。在過去,我能夠在另一個應用程序中實現這樣的效果,但這對我來說似乎不起作用。所有對這種情況至關重要的方法都會被調用,並且該行很好地擴展,但showExpandedContents方法中的additionalInfo表不會顯示!添加UIView重用UITableViewCell?

  • 如果我創建additionalInfo表中的單元格的初始化,該表將出現,但是當我然後嘗試加載數據(並通過,也細胞),它只是不會重新加載表格。 但是負責這個(showExpandedContents)表的方法肯定會被調用。
  • 如果我初始化在單元格的初始化代碼中設置表格一切正常。

所以這裏是給你一些代碼:

這裏是小區建立:

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

    static NSString *cellID = @"MyCustomCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; 

    if(cell == nil){ 
     cell = [[MyCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; 
    } 

    ((MyCustomCell*)cell).data = [arrayToDisplay objectAtIndex:indexPath.row]; 


    return cell; 
} 

下面是選擇方法:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 


    [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; 
    //setting the current cell as the expandedRow, so that I can collapse it later 
    expandedRow = [tableView cellForRowAtIndexPath:indexPath]; 
    [((MyCustomCell*)expandedRow) showExpandedContents]; 
    [tableView beginUpdates]; 
    [self changeRowHeightAtIndex:indexPath.row height:330]; 
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 
    [tableView endUpdates]; 



} 

這裏是在-showExpandedContents方法MyCustomCell我想在其中顯示附加信息:

-(void)showExpandedContents{ 

    additionalInfo = [[UITableView alloc] initWithFrame:CGRectMake(0, 80, self.frame.size.width, 250)]; 
    [additionalInfo loadContent]; 
    additionalInfo.backgroundColor = UIColorFromRGB(0xf9f9f9, 1.0); 
    additionalInfo.layer.zPosition = MAXFLOAT; 
    [self.contentView addSubview:additionalInfo]; 

} 

回答

1

看起來你

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 

是給你一個新鮮細胞,比一個有showExpandedContents叫法不同。

刪除此行應解決該問題。

+0

哦,閣下!這種從互聯網上盲目複製的內容造成了如此多的絕望!非常感謝! –

+0

酷!現在我很好奇你將如何在不重新加載單元格的情況下製作出漂亮的動畫。請分享,當你有它。 –

+0

我不太清楚你的意思。我通過簡單地刪除線來解決問題。選擇該單元格後,它會展開並顯示其他信息。 –