2013-04-18 30 views
0

我遵循this教程爲了創建一個自定義單元格。Monotouch iphone定製UITableView

我創建的界面生成器自定義單元格,看起來像: enter image description here

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

myTable.Source = new 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; 
    } 

問題是,顯示在最後看起來像這樣:

enter image description here

這似乎有某種重疊。任何想法爲什麼會發生?

謝謝!

回答

1

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

如果每行的高度不同,可以在委託中使用GetHeightForRow,但這會慢很多,導致表視圖在第一次呈現之前遍歷所有單元格(因此它可以計算滾動高度)。

+0

謝謝!它解決了我的問題:) –

0

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