![](/img/trans.png)
[英]Monotouch application is getting crashed in device but works fine in simulator
[英]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.