Need help with understanding navigation using Monotouch.Dialog and subclassed RootElement

KevelopKevelop NLMember ✭✭

In my DialogViewcontroller, my Root looks something like this (simplified)

Root = new RootElement("settings") { 
new Section("1") { new SubClassedRootElement("mylist A"), new SubClassedRootElement("mylist B")},
new Section("2") { new StringElement("just"), new StringElement("some"), new StringElement("others")}
}

Now, my class SubClassedRootElement, just adds a list of items programmatically in it's constructor, like so:

        this.Add(new Section());
        this[0].AddAll(GetElementsFromDataStore());

so far, so good. When i tap one of my subclassed root elements, a new view is being pushed, the navigationbar shows the back button and the long list of elements from the datasource is shown.

Now, i want on this view, to add a RightButtonBar to the Navigationbar, to be able to reorder those elements.

I chose to do this by overriding the
Selected(DialogViewController dvc, UITableView tableView, NSIndexPath path) method of my subclassed rootelement. And there i do:

dvc.NavigationItem.SetRightBarButtonItem(...)

What happens is: This right button is presented on the Navigation Bar, BEFORE the new view is pushed. I can see it when i tap the back button.
What i want is: Put this button on the navigation bar in the view after the new view is pushed.

I really have no clue how to do this right now... so any help is greatly appreciated! :)

Posts

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    @Kevin010,

    Once you start wanting to customize DialogViewControllers, you should break out your screens so that you can customize them correctly. Instead of having a bunch of SubClassedRootElements, you can make a subclassed DialogViewController and have access to the controller life cycle methods. I think that is the proper place to set navigation items e.g. in ViewDidLoad().

    Something like this:

    public class MyListViewController : DialogViewController
    

    Now you have access to ViewDidLoad, etc. You can do the work in there. You can also build your Root in there to display your list.

    To navigate to that screen, you can either use a UINavigationController or there is an override for RootElement that has something like createControllerOnSelected and you can create your MyListViewController. I hope that helps!

Sign In or Register to comment.