2013-04-18 32 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)中的相同。