繁体   English   中英

GetViewForHeader可在模拟器中工作,但不能在设备上工作

[英]GetViewForHeader works in the simulator but not working on the device

所以我有一个GetViewForHeader重写,它在模拟器中很好用。 当我在设备(iPad和iPhone)上调试应用程序时,未应用任何样式。 没有错误,并且绝对不会运行GetViewForHeader代码。 TitleForHeader等是。 奇!

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

仅当GetHeightForHeader返回非零整数时才调用GetViewForHeader方法,因此请确保您正在实现GetHeightForHeader方法并返回适当的高度。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM