3

I have a Custom element class that only resizes the rows when I rotate the device. On initial display the rows are not resized.

public class MultiImageElement : Element, IElementSizing

Which implements the IElementSizing interface:

    #region IElementSizing implementation
    public float GetHeight (UITableView tableView, NSIndexPath indexPath)
    {
        return 78;
    }
    #endregion

However, this is never called and the row heights remain the default size.

I add elements to my root in a loop:

for (int i = 0; i < secFolder.Rows; i++)
{
   sec.Add (new MultiImageElement (secFolder.ThumbnailPathsForRow (i), imageSize));
}
this.Root.Add (sec);
Ian Vink
  • 66,960
  • 104
  • 341
  • 555

3 Answers3

4

I found the solution.

To have Monotouch.Dialog implement the IElementSizing, the Sections and Elements must be added to a local "myRoot" variable.

After it's been built out, then set the Dialog's Root to that.

var myRoot = new Root();
MakeElements()
this.Root = myRoot;

This works.

Ian Vink
  • 66,960
  • 104
  • 341
  • 555
3

Another solution is custom DialogViewController and then setup Root.UevenRows to true:

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

Might not be related, but happened to me that the initial rotate device event was not fired to me. So I implemented the flag and initiated a scheduled selector to be called upon app start to ensure the ShouldAutorotate... was called and performed the Layout for me if needed.

Pavel Sich
  • 1,299
  • 10
  • 10