MonoTouch.Dialog.DialogViewController and UINavigationController: missing back button

Ran in to an issue where I was pushing several DialogViewControllers in to a NavigationController. The DialogViewcontroller instances would asynchronously fetch data, and add the dialog elements when the data was retreived. Whilst this was working quite well, at any given point in the navigation the back button would only appear on the topmost view (the current view). Navigate back to any previous view and the back button would not be on the NavigationController.

I knew that the NavigationController is reliant upon the title of each UIView, so I made sure I was setting that, but it didn’t help.

The solution was to make sure to not reinstantiate the Root element of the DialogViewController. Doing so must mess with the Title of the UIView, and even if ithe title content stays the same, it looks like it causes the NavigationController to forget what it’s called and prevent a back button from showing. Instead, instantiate the RootElement when the class is created, and add items to the that object when the data has been retreived.

Bad:

//data has been retreived, replace dialog contents
this.Root = new RootElement(myTitle)
{
new Section("Folders"){
Elements = myData.Select(obj => (Element)new StringElement(obj.Name)).ToList()
}
};

Good:

//data has been retreived, replace dialog contents
this.Root.Clear();
this.Root.Add(new Section[]
{
new Section("Folders"){
Elements = myData.Select(obj => (Element)new StringElement(obj.Name)).ToList()
}
});
About these ads

6 thoughts on “MonoTouch.Dialog.DialogViewController and UINavigationController: missing back button

  1. Hello,
    I have a standard navigation controller like:
    navigationController = new UINavigationController(memberSelectController);
    and I would like to a Monotouch.Dialog to it.
    That works:
    MemberDialogController controller = new MemberDialogController(SelectedMember);
    controller.Title=”Member Info”;
    NavigationController.PushViewController(controller,true);

    However the dialog is show, but there is no back button. Is it possible to add a monotouch dialogue from a ‘standard’ UINavigationController’

    thanks for your help

      • memberSelectController.Title=”Leden Lijst”;

        MemberDialogController controller = new MemberDialogController(SelectedMember);
        controller.Title=”Info”;
        NavigationController.PushViewController(controller,true);

        but no succes

      • For me it was changing constructor to call base(style…, null, true) – parameter pushing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s