0

I am looking for a way to change screens when the GlassButton is clicked. I have just started learning Monotouch.Dialog. I have done the following to try and handle this.

public override void ViewDidLoad ()
    {

        button.TouchUpInside += (sender, e) => {
            this.NavigationController.PushViewController(list, true);
        };
    } 

list is a UIViewController, but on click, this.NavigationController.PushViewController(list, true); is pointed to with a null reference exception. list has been instantiated and is not null, however, this.NavigationController is null. How can I fix this?

GlassButton button = new GlassButton (new RectangleF(0, 0, 200, 50));
List list = new List ();
public static EntryElement lastName = new EntryElement (null, "Enter Last Name", null);
public static EntryElement firstName = new EntryElement (null, "Enter First Name", null);
public static EntryElement middleInitial = new EntryElement (null, "Enter Middle Initial", null);

    public practice () : base (UITableViewStyle.Grouped, null)
    {
        Root = new RootElement ("Level 1") {
            new Section() {
                new RootElement("Level 2") {
                    new Section("Individual Information") {
                        lastName, firstName, middleInitial
                    },

                    new Section("Submit") {
                        button
                    }
                }
            }
        };
    }
SoftSan
  • 2,482
  • 3
  • 23
  • 54
Yahiko Kikikoto
  • 688
  • 3
  • 12
  • 23

1 Answers1

0

I had the same issue and resolve by deriving subclass from DialogViewController

public class CustomDialogViewController : DialogViewController
{
        public CustomDialogViewController(RootElement root)
            : base(null, true)
        {
            base.Root = root;
        }
}

In my main view controller i used following in my ViewDidLoad():

var root = new RootElement("Customer form");
// code to generate section and add into root
CustomDialogViewController customDialogViewController = new CustomDialogViewController(root);
var navigationController = new UINavigationController(customDialogViewController);

this.AddChildViewController(this.navigationController);
this.View.AddSubview(this.navigationController.View);
SoftSan
  • 2,482
  • 3
  • 23
  • 54