Monotouch.Dialog: 没有使用IElementSizing

3
我有一个自定义元素类,只有在旋转设备时才会调整行的大小。在初始显示时,行不会被调整大小。
public class MultiImageElement : Element, IElementSizing

实现IElementSizing接口的方法如下:
    #region IElementSizing implementation
    public float GetHeight (UITableView tableView, NSIndexPath indexPath)
    {
        return 78;
    }
    #endregion

然而,这个方法从未被调用,行高仍保持默认大小。

我在循环中向根元素添加元素:

for (int i = 0; i < secFolder.Rows; i++)
{
   sec.Add (new MultiImageElement (secFolder.ThumbnailPathsForRow (i), imageSize));
}
this.Root.Add (sec);
3个回答

4
我找到了解决方案。
为了让Monotouch.Dialog实现IElementSizing,必须将Sections和Elements添加到本地的“myRoot”变量中。
构建完成后,将对话框的根设置为该变量。
var myRoot = new Root();
MakeElements()
this.Root = myRoot;

这是有效的。


3

另一种解决方案是自定义DialogViewController,然后将Root.UnevenRows设置为true:

    public class CustomViewController : DialogViewController
    {
        public CustomViewController (RootElement root) : base(root)
        {
            Root.UnevenRows = true;
            ...
        }
        ...
     }

1

可能与此无关,但我遇到过初始旋转设备事件没有触发的情况。因此,我实现了一个标志,并在应用程序启动时初始化了一个计划选择器,以确保调用ShouldAutorotate...并在需要时为我执行布局。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接