2014-05-12 260 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'關鍵字。否則,解決這些問題很可能會暴露另一個問題。 –

相關問題