Xamarin iOS - 刷新视图从另一个视图返回

时间:2016-04-26 23:35:09

标签: uiviewcontroller xamarin xamarin.ios

我有一个View 1(UIViewController),它有一个导航到新视图的按钮 - View 2(UIViewController)。

当用户点击View 2中的按钮时,我想刷新View 1. UIViewController没有ViewWillAppear知道控件又返回到视图上。

如何确定控件是否在该视图上传递

3 个答案:

答案 0 :(得分:0)

您可以覆盖ViewDidAppear以检测视图1是否再次可见并刷新视图。不要忘记调用基本方法。

public override void ViewDidAppear(bool animated)
{
    base.ViewDidAppear (animated);
    //Refresh view here.
}

答案 1 :(得分:0)

  

UIViewController没有ViewWillAppear

ViewWillAppear上没有方法UIViewController

您可以尝试使用UINavigationControllerDelegate,特别是WillShowViewController

答案 2 :(得分:0)

1)我们可以用bool值设置它。

bool viewLoadedAgain =  false;

2)当segue触发时,Bool值变为'true':

public override void PrepareForSegue (UIStoryboardSegue segue, Foundation.NSObject sender)
        {
            base.PrepareForSegue (segue, sender);

            if(segue.Identifier == "segueToSecondVC")
            {
                viewLoadedAgain = true;

            }
        }

3)执行刷新ViewController视图。

public override void ViewWillAppear (bool animated)
{
    base.ViewWillAppear (animated);
    this.PerformSegue ("segueToSecondVC",this);

    if(viewLoadedAgain ==  true)
    {
        //Use any code as per requirement
        this.View.SetNeedsLayout ();
        this.View.SetNeedsUpdateConstraints ();
        this.View.ReloadInputViews ();
        this.View.SetNeedsDisplay ();

    }
}