1

When an item is clicked, a details view controller is opened that makes some webservice calls to save back the data if the user clicks save (this works fine). The issue I have is after saving the data when the user clicks back to go back to the list, the list item (ie if the name was updated) is not updated. So, perhaps the user changes the name and so the list prior should be updated, I'd like to update the value without having to make another webservice call to repopulate.

I am calling this.ReloadData() when the view appears, but this never seems to update the list names. I've checked workouts which is a list of objects, and it has been modified by the detail controller, however the reload data doesn't seem to do anything.

How do I refresh the data in the case that another controller has modified the list of objects.

public override void ViewWillAppear (bool animated)
    {
        InvokeOnMainThread (delegate {                      
            this.ReloadData();
        }); // call reload on main thread

                    base.ViewWillAppear (animated);
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        workouts = manager.GetWorkouts(Helpers.User.Auth);
        var sections = new Section();
        var root = new RootElement("Workouts"){sections};
        foreach (var wo in workouts) {
            var tempwo = wo;
            var wodetail = new RootElement(wo.Name, delegate {
                var W = new WorkoutViewModel(tempwo);
                var p = new WorkoutDetailController(W, tempwo);
                return p;
            });
            sections.Add (wodetail);            
        }

        Root = root;
    }
4

1 に答える 1

1

カスタムオブジェクトから要素の値を次のように割り当てると、次のようになります。

AccountDetailsSection = new Section ("Details"){
            new StringElement ("Code:",  _Account.Code),
            new StringElement ("Name:",  _Account.Name) };

目的の結果が得られますが、要素はオブジェクトのプロパティへのポインターを失います。したがって、後でプロパティの値を変更すると、たとえば次のようになります。

_Account.Code = "xxx";

データをリロードしても何も起こりません。次のように値を手動で更新する必要があります。

(AccountDetailsSection.Elements [0] as StringElement).Value = "xxx";
this.Root.Reload ( AccountDetailsSection, UITableViewRowAnimation.Fade);

お役に立てれば。

于 2013-03-07T10:17:14.787 に答える