Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:23:37+00:00 2026-05-31T16:23:37+00:00

I am writing a view controller for adding a new item to my app.

  • 0

I am writing a view controller for adding a new item to my app. It is a perfect fit for MonoTouch.Dialog, as it can be done easily with a table based interface, with a field per relevant property of my item.

This is the code I have currently for showing the add item view (simplified, but the core idea remains):

Item item = new Item();
TapHandler handler = new TapHandler(); 
BindingContext bc = new BindingContext(handler, item, "Add Item");
DialogViewController dv = new DialogViewController(bc.Root, true);
this.NavigationController.PushViewController(dv, true);

While that works, I would prefer if I could encapsulate the details of the view into its own view controller, so the code could look like this:

UIViewController controller = new AddItemViewController();
this.NavigationController.PushViewController(controller, true);

However, I can’t figure out how to implement this. I thought the logical thing to do would be to make a subclass of DialogViewController. However, all the constructors of DialogViewController require a RootElement. To get that, you need to firstly create the BindingContext. As you can’t run any code before calling the base constructor, it doesn’t end up working.

My second approach was to implement subclass of UIViewController, create the DialogViewController, and the add the dialog view controller as a child of my subclass using this.AddChildViewController(dv) and this.View.AddSubView(dv.View). While this works initially, if you have the new view controller in a UINavigationController, and you click a date element, the date view appears as a modal popup rather than in the navigation controller hierarchy. (This makes sense, as the DialogViewController isn’t part of the NavigationController hierarchy in this design).

From there I’m stuck. I couldn’t find any examples of using MonoTouch.Dialog like this in the examples either. Is this possible to do? Or if it’s not, is there a good reason as to why writing code like this is a bad idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:23:38+00:00Added an answer on May 31, 2026 at 4:23 pm

    I found a way to do this, although it seems a little messy (thanks poupou for giving me the idea). I just set Root to null in the base constructor call, and then set it straight away in the contructor method:

    class NewItemViewController : DialogViewController
    {
        private Item _item;
        public NewItemViewController(bool pushing) : base(null, pushing)
        {
            _item = new Item();
            BindingContext bc = new BindingContext(this, _item, "Add Item");
            this.Root = bc.Root;
            // more setup
        }
        // more methods
    }
    

    I wasn’t aware you could change the Root object, not just access it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an iOS app with a table view inside a tab view. In
I'm writing an iPhone app. Starting from a view controller in a navigation stack
I want to use the Model-View-Controller template while writing my Web App. The problem
When writing the usual view controller code, can I assume that this will only
I'm writing a Silverlight app using the MVVM pattern. I have a main view
I was writing a simple custom View Controller in ios5 with a UIScrollView and
I'm writing my first application with Zendframework. My question is about the Model–View–Controller (MVC)
I am writing an iPhone application that contains a tab controller, each tab item
I am writing an iPad app and am very new to objective C. I
I'm writing a drawing application that shows a tools view controller when the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.