簡體   English   中英

Monotouch UITableViewCell AddSubView

[英]Monotouch UITableViewCell AddSubView

我正在嘗試創建一個類似於視圖的表/網格,我可以用它來顯示大量信息。

我嘗試實現此目的的方法是創建自定義單元格視圖。 它基本上是UINavigationController ,我知道這是不正確的,因為它需要是一個UIView才能將它添加到UITableViewCell.ContentView.AddSubView(UiView view)

它看起來像這樣:

在此輸入圖像描述

然后在我的表源GetCell()我有這個。

public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
    int rowIndex = indexPath.Row;
    Incident _incident = tableData[rowIndex];

    UITableViewCell cell = tableView.DequeueReusableCell(cellID);
    if(cell == null)
        cell = new UITableViewCell(UITableViewCellStyle.Default, cellID);

    CustomCellView content = new CustomCellView();
    content.SetRef(_incident.Id);
    content.SetDescription(_incident.Description);

    cell.ContentView.Add(content);
    return  cell;
}

它的cell.ContentView.Add是我出錯的地方? 我只需要將我在IB中創建的自定義視圖添加到單元格內容中。

我認為這個答案將幫助您將Xcode / InterfaceBuilder NIB文件與UITableViewCell

要記住的一件重要事情是,你(經常) 重新使用細胞,它們將處於你離開它們的狀態。

因此,如果您每次重復使用單元格時添加(例如AddAddSubview )並且永遠不會刪除視圖(或子視圖...),那么您的內存使用量將隨着時間的推移而增長(滾動表格時可能會非常快速地發生)。

我自己想出來了。 我沒有繼承正確的觀點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM