0

monotouch.dialog タスク サンプル アプリ (http://docs.xamarin.com/ios/Guides/User_Interface/MonoTouch.Dialog/Elements_API_Walkthrough) のコードに従っています。

私がうまくいかないように見えるのは、ユーザーが + ボタンをクリックすると、テーブルに新しい行が追加されることです。ユーザーはこれをタッチして、情報を入力できる別の画面に移動します。ここで、ルート ビューに戻るときに、rootElements のリストを更新して、デフォルト名の「connection」の代わりに入力した名前が使用されるようにします。

入力内容に基づいて、各 RootElements のテキストを更新するにはどうすればよいですか?

すべてが理にかなっていることを願っています!

-- 以下のコード。

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;
    }
}

と :

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; }
}
4

1 に答える 1

1

このように試しましたthis.ReloadData();か?

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();
}

それに関する他のトピックはこちらにあります。

編集

これは AppDelegate にあると言い忘れていましたが、これはあなたがしていることのために作られたものではありません。

最初に、DialogViewController を作成します: Project > Add new file > MonoTouch > DialogViewController。そして、先ほど述べた別のメソッドに ReloadData() メソッドを入れます。これらのメソッド (ViewDidLoad、WillAppear など) は、UIView のオーバーライド メソッドです。AppDelegate は、起動前にデータを取得したり、アプリの静的データを保存したりするために存在します。全く違う使い方です。

AppDelegate の場合、たとえば次のようにする必要があります。

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;
}
于 2012-11-07T13:47:31.923 に答える