2

I'm using MonoTouch.Dialog on an iPad screen.

I have created a fullscreen background on which I have a MonoTouch.Dialog Table plotted.

I wish to change the width of the MonoTouch.Dialog Table (or of all the cells), while leaving the fullscreen background in place. How can I do this?

1 Answers1

0

You can not do this directly because a DialogViewController's is similar to a UITableViewController and UITableView which have some traits to fill its containing space. There is a clever trick to get around this where you will need to create a "container" UIView for the width you want and add it as a subview to a UIViewController. Now make your DialogViewController and add its View as a subview of that container. The Dialog will expand to the size of the container, rather than the parent view.

You should end up with something like this:

public class MyController : UIViewController
{
    UIView container;
    DialogViewController dvc;

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        container = new UIView();
        dvc = new DialogViewController(UITableViewStyle.Grouped, null, true);
        dvc.Root = new Root("Title") {
            new Section() {
                new StringElement("Hello")
            }
        };

        View.AddSubview(container);
    }

    public override void ViewDidLayoutSubviews()
    {
        base.ViewDidLayoutSubviews();

        // Whatever width you want
        float newWidth = View.Bounds.Width / 2;
        container.Frame = new RectangleF(0, 0, newWidth, View.Bounds.Height);

        // This is a workaround so that the TableView fills the container view 
        // after it is sized. 
        container.AddSubView(dvc.View);
    }
}
valdetero
  • 4,624
  • 1
  • 31
  • 46
therealjohn
  • 2,378
  • 3
  • 23
  • 39