2016-04-26 63 views
0

我有一個視圖1(UIViewController),它有一個按鈕導航到一個新的視圖 - 視圖2(UIViewController)。Xamarin iOS - 刷新查看從其他視圖回來

我想刷新查看1當用戶從查看2單擊後退按鈕。UIViewController沒有ViewWillAppear知道控制回到視圖。

如何確定控制進入該視圖

+0

我不清楚這個問題。你想刷新整個視圖? –

回答

0

您可以覆蓋ViewDidAppear再次檢測查看1可見,並且刷新視圖。不要忘記調用基本方法。

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

1)我們可以用一個布爾值進行設置。

bool viewLoadedAgain = false; 

2)布爾值變 '真' 時,賽格瑞觸發:

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

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

      } 
     } 

3)執行刷新視圖控制器視圖。

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

    } 
}