2014-05-12 198 views
1

所以我有一个GetViewForHeader覆盖,它在模拟器中工作得很好。当我调试设备上的应用程序(包括iPad和iPhone)时,不会应用样式。没有错误,GetViewForHeader代码肯定不会运行。 TitleForHeader等是tho。奇!GetViewForHeader在模拟器中工作,但不在设备上工作

public override string TitleForHeader (UITableView tableView, int section) 
{ 
    return tableItems[section].Name; 
} 

public override UIView GetViewForHeader(UITableView tableView, int section) 
{ 
    // THIS DOES NOT FIRE ON THE DEVICE - BUT IT DOES ON THE SIMULATOR 
    return BuildSectionHeaderView(tableItems[section].Name); 
} 

public static UIView BuildSectionHeaderView(string caption) { 
    UIView view = new UIView(new System.Drawing.RectangleF(0,0,320,20)); 
    view.BackgroundColor = UIColor.White; 

    UILabel label = new UILabel(); 
    label.Opaque = false; 
    label.TextColor = UIColor.FromRGB (190, 0, 0); 
    label.Font = UIFont.FromName("Helvetica-Bold", 16f); 
    label.Frame = new System.Drawing.RectangleF(5,10,315,20); 
    label.Text = caption; 
    view.AddSubview(label); 
    return view; 
} 

回答

1

如果GetHeightForHeader返回非零整数GetViewForHeader方法只调用,因此确保您实现GetHeightForHeader方法并返回合适的高度。

还值得注意的是,如果使用标题视图,则不应该实现TitleForHeader方法。

+0

我现在编辑了代码 - 删除了TiteForHeader并添加了GetHeightForHeader。我现在得到一个不同的错误:类型'MonoTouch.Foundation.You_Should_Not_Call_base_In_This_Method'的异常被抛出。 –

+0

错误是来自同一地点还是来自另一个文件?我猜测没有看到更多的代码,但我可以建议的是,你确定你确实在你的'GetHeightForHeader'方法中使用'override'关键字。否则,解决这些问题很可能会暴露另一个问题。 –

相关问题