簡體   English   中英

Monotouch iPhone定制UITableView

[英]Monotouch iphone custom UITableView

我按照教程進行操作以創建自定義單元。

我已經在Interface Builder中創建了一個自定義單元格,如下所示: 在此處輸入圖片說明

在我的ViewController中,我添加了一個UITableView並將其綁定到數據:

myTable.Source = new ListSource();

ListSource的GetCell方法:

public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
    { 
        // Reuse a cell if one exists 
        CustomListCell cell = tableView.DequeueReusableCell ("QCell") as CustomQuestionsListCell;

        if (cell == null)
        {  
            // We have to allocate a cell 
            var views = NSBundle.MainBundle.LoadNib ("CustomListCell", tableView, null); 
            cell = Runtime.GetNSObject (views.ValueAt (0)) as CustomListCell;
        } 

        return cell; 
    }  

問題在於最后的顯示如下:

在此處輸入圖片說明

好像有點重疊。 任何想法為什么會這樣?

謝謝!

您需要將表視圖的RowHeight設置為IB中的任何視圖高度。 這應該是myTable.RowHeight = ...

如果每行的高度不同,則可以在委托中使用GetHeightForRow ,但這會慢得多,從而導致表視圖在第一個呈現之前遍歷所有單元格(以便可以計算滾動高度)。

您需要為項目中使用的自定義單元格設置RowHeight。 由於您沒有提供任何高度,因此Table將默認值分配給TableViewCell。 您提供的RowHeight應該與Interface Builder(IB)中的RowHeight相同。

暫無
暫無

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

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