使用的MonoTouch 5.2.11的iOSMonoTouch的對話框定義元素和getHeight沒有被調用
我按照本教程(http://tirania.org/monomac/archive/2011/Jan-18.html),創建了圖像的自定義單元格和還添加了IElementSizing接口。 GetHeight永遠不會被調用。
已經提出了類似的問題,普遍接受的解決方案是首先確定並創建RootElements,然後將它們添加到控制器之前設置UnEvenRows = true。這沒有奏效。我已經嘗試過以及將其他部分添加到根元素的其他組合,並且從未見過GetHeight被解僱。
MyDataElement是一個320x200的圖像,它顯示正常,但沒有顯示它後面的字符串元素(假設它在後面)。因此,如果我將自定義單元格拖到頂部以上,它就會消失,重新出現,並在其上顯示第二個嚴格單元。
這裏是我試過的代碼:
public class MyDataElement : Element, IElementSizing {
static NSString key = new NSString ("myDataElement");
public MyData MyData;
public MyDataElement (MyData myData) : base (null)
{
MyData = myData;
}
public float GetHeight (UITableView tableView, NSIndexPath indexPath){
return 200f; // break point here is never hit ever
}
public override UITableViewCell GetCell (UITableView tv)
{
var cell = tv.DequeueReusableCell (key) as MyDataCell;
if (cell == null)
cell = new MyDataCell (MyData, key);
else
cell.UpdateCell (MyData);
return cell;
}
public partial class TableTester : DialogViewController
{
public TableTester() : base (UITableViewStyle.Grouped, null)
{
var re = new RootElement("Sample") {
new Section("Testy") {
new MyDataElement(new MyData() { stuff="hello"}),
new StringElement("Sample")
}
};
re.UnevenRows = true;
this.Root = re;
//this.Root = root;
}
}
除此之外我甚至做到了這一點,沒有工作之一:
public class TestNavigator : UINavigationController {
public TestNavigator() {
TabBarItem = new UITabBarItem("Test", null, 1);
var re = new RootElement("Sample") {
new Section("Sammy") {
new StringElement("Sample"),
new MyDataElement(new MyData() { stuff="sam"}),
new StringElement("Sample 2")
}
};
re.UnevenRows = true;
var dv = new DialogViewController(re);
re.UnevenRows = true;
PushViewController(dv, true);
}
我已經從github下載Monotouch.Dialog來檢查ImageLoader代碼,並將它用作我項目中的參考。刪除引用並使用內置的Monotouch.Dialog後,問題已得到修復。 IElementSizing不能從github工作: –
lucuma
您粘貼的文本不足以重現問題。但總的來說,UnevenRows屬性是自動計算的,設置它不會真的爲你做很多 –
謝謝。當我從github下載的項目中移除Monolog.Dialog引用並使用內置的項目時,它已經修復。 – lucuma