【问题标题】:Monotouch iphone custom UITableViewMonotouch iphone 自定义 UITableView
【发布时间】:2013-04-18 23:55:05
【问题描述】:

我按照this 教程来创建自定义单元格。

我在 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; 
    }  

问题是最后的显示是这样的:

似乎有某种重叠。任何想法为什么会发生这种情况?

谢谢!

【问题讨论】:

    标签: c# iphone uitableview xamarin.ios xamarin


    【解决方案1】:

    您需要将表格视图的RowHeight 设置为IB 中的任何视图高度。这应该是myTable.RowHeight = ...

    如果每行有不同的高度,可以在委托中使用GetHeightForRow,但这会慢得多,导致表格视图在第一次渲染之前遍历所有单元格(因此它可以计算滚动高度)。

    【讨论】:

      【解决方案2】:

      您需要为您在项目中使用的自定义单元格设置行高。由于您没有提供任何 height ,因此 Table 将默认分配给 TableViewCell 。您提供的 RowHeight 应与 Interface Builder (IB) 中的相同。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多