Saturday, March 2, 2013

ViewWillDisappear ViewWillAppear Monotouch.

When you deal in buttons, you need to make sure in your ViewWillDisappear, and your ViewWillAppear, that you subscribe to events for your buttons and unsubscribe.   Just so that while the new view is being presented, you don't get hit with an error.

        EventHandler StatusClick;
        EventHandler ConditionClick;
        EventHandler PhotoClick;

public override void ViewWillAppear (bool animated)
            base.ViewWillAppear (animated);
            StatusClick = delegate {
                DisplayStatus ();
            ConditionClick = delegate {
            PhotoClick = delegate {
            this.Condition.TouchUpInside += ConditionClick;
            this.Status.TouchUpInside += StatusClick;
            this.Photo.TouchUpInside += PhotoClick;
        public override void ViewWillDisappear (bool animated)
            base.ViewWillDisappear (animated);
            this.Status.TouchUpInside -= StatusClick;
            this.Condition.TouchUpInside -= ConditionClick;
            this.Photo.TouchUpInside -= PhotoClick;

No comments:

Post a Comment