【问题标题】:Xamarin iOS - Refresh View coming back from another viewXamarin iOS - 从另一个视图返回的刷新视图
【发布时间】:2016-04-27 17:28:41
【问题描述】:

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

当用户从视图 2 中单击返回按钮时,我想刷新视图 1。UIViewController 没有 ViewWillAppear 知道控件返回视图。

如何确定控件是在那个视图上传递的

【问题讨论】:

  • 我不清楚这个问题。是否要刷新整个视图?

标签: uiviewcontroller xamarin xamarin.ios


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    UIViewController 没有 ViewWillAppear

    UIViewController 上没有方法 ViewWillAppear

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

    【讨论】:

      【解决方案3】:

      1)我们可以设置一个布尔值。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-01-08
        • 1970-01-01
        • 2012-08-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多