0

I have been following the code from the monotouch.dialog task sample app (http://docs.xamarin.com/ios/Guides/User_Interface/MonoTouch.Dialog/Elements_API_Walkthrough).

Something I dont seem able to work out, is when the user clicks the + button a new row to the table is added. The user touches this and navigates to another screen where they can enter information. Now, when they navigate back to the root view, I want the list of rootElements to be updated so the entered name is used instead of the default name 'connection'

How would I go about updating the text for each of the RootElements based upon what has been entered?

I hope that all makes sense!

-- code below.

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
    window = new UIWindow (UIScreen.MainScreen.Bounds);

    RootElement _rootElement = new RootElement ("To Do List"){ new Section()};

    DialogViewController _rootVC = new DialogViewController (_rootElement);

    // This adds an 'add' button to the root view controller, and handles by delegate,the push to a screen where you can add a new vCenter connection profile.
    UIBarButtonItem _addButton = new UIBarButtonItem (UIBarButtonSystemItem.Add);
    _rootVC.NavigationItem.RightBarButtonItem = _addButton;

    _addButton.Clicked += (sender, e) =>  {
        var connectionProfile = new connectionProfile{};
        // See, on the line below, I add a default RootElement with the text New Connection.

        var connectionProfileElements = new RootElement ("New Connection") {
            new Section () {
                // When they enter the name on the next line of code, I want to use this to update the New Connection text on the root screen.
                new EntryElement ("Name", "Enter Connection Name", connectionProfile._connectionName),
                new EntryElement ("VC Address", "Enter VC Address", connectionProfile._address),
                new EntryElement ("VC Port", "Enter VC Port", connectionProfile._port),
                new EntryElement ("Username", "Enter Username", connectionProfile._userID),
                new EntryElement ("Password", "Enter Password", connectionProfile._password,true)}      
            };
            _rootElement [0].Add (connectionProfileElements);
        };

        UINavigationController _nav = new UINavigationController (_rootVC);
        window.RootViewController = _nav;
        window.MakeKeyAndVisible ();

        return true;
    }
}

And :

public class connectionProfile
{
public connectionProfile ()
    {
    }

    public string _connectionName { get; set; }
    public string _address { get; set; }
    public string _port { get; set; }
    public string _userID {get; set; }
    public string _password { get; set; }
}
Nate B.
  • 942
  • 11
  • 31
Paul Davey
  • 87
  • 1
  • 8
  • I believe in simplified terms, what I am asking is: Given a RootElement with a default 'caption' of New Connection, how what event do I need to override/handle to update this with the connectionprofile._connectionName once it has been entered and the user is navigating back to the table view? – Paul Davey Nov 07 '12 at 10:44

1 Answers1

1

Did you try this.ReloadData(); like this ?

public NameOfYourDialogViewController() : base (UITableViewStyle.Grouped, null)
{
    Root = new RootElement ("test") {
        new Section ("First Section"){
            new StringElement ("Hello", () => {
                new UIAlertView ("Hola", "Thanks for tapping!", null, "Continue").Show (); 
            }),
            new EntryElement ("Name", "Enter your name", String.Empty)
        },
        new Section ("Second Section"){
        },
    };
    }
}
public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    // Do your stuff
}

public override void ViewWillAppear (bool animated)
{
    base.ViewWillAppear (animated);
    this.ReloadData();
}

You can find other topic about that here.

EDIT

You forgot to say that this is located in your AppDelegate, which is not made for what you are doing.

At first, create a DialogViewController: Project > Add new file > MonoTouch > DialogViewController. And in the different method I mentioned earlier, put the ReloadData() method. These methods (ViewDidLoad, WillAppear and so on) are override methods from UIView. AppDelegate exists to get data before your is launched, store static data for your app, and so on. It's completly different usage.

And for your AppDelegate, you should have this for example:

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
    _window = new UIWindow (UIScreen.MainScreen.Bounds);
    _controller = new NameOfYourDialogViewController();

    _navigationController = new UINavigationController (_controller);

    UIImageView splash = new UIImageView(_window.Bounds);
    splash.Image = UIImage.FromFile("Default.png");

    _window.AddSubview(splash);
    _window.AddSubview(_navigationController.View);
    _window.BringSubviewToFront(splash);

    _window.MakeKeyAndVisible ();

    // This is used to create a fadding effect in your splashscreen
    UIView.Animate(1,
            delegate { splash.Alpha = 0f; },
            delegate {
                _window.RootViewController = _navigationController;
                splash.RemoveFromSuperview();
            });
    return true;
}
Community
  • 1
  • 1
Nate B.
  • 942
  • 11
  • 31
  • I cannot add the ViewWillAppear section, it errors in the editor but I dont know why? I have attached my project here: https://www.dropbox.com/s/kaonx1vh7xp8zyg/Archive.zip Any and all help is really appreciated – Paul Davey Nov 07 '12 at 14:05
  • I edited my answer with a better and most complete answer. :) I hope that helped. – Nate B. Nov 07 '12 at 14:36