2012-04-15 32 views
1

我有一個UITabBarController,它承載5個UINavigationControllers(我們稱之爲N1-N5)。 UINavigationControllers中的每個UI元素都會導致UITableViewController被推送到導航堆棧上(我使用MonoTouch.DialogDialogViewController來實現這些UITableViewControllers)。我們稱之爲T1 - T5。ViewDid出現在UINavigationController上時沒有被調用返回

當我在選項卡之間導航時,將按照預期方式在N1-N5上調用ViewDidAppear方法。但是當我觸及N1上的UI元素時,會導致T1被推入導航堆棧,然後嘗試返回使用後退按鈕,N1的ViewDidAppear方法不會被調用。

有趣的是,如果我「換到」不同的選項卡(比如N2),然後「退回」到N1,ViewDidAppear將被視爲正常。即使我將T1推入導航堆棧,如果我做同樣的Tab鍵,N1的ViewDidAppear仍然會被調用。

爲N1的MonoTouch代碼如下所示:

public class CalendarPage : UINavigationController 
{ 
    private DialogViewController dvc; 

    public override void ViewDidAppear (bool animated) 
    {   
     // initialize controls 
     var now = DateTime.Today; 
     var root = new RootElement("Calendar") 
     { 
      from it in App.ViewModel.Items 
       where it.Due != null && it.Due >= now 
       orderby it.Due ascending 
       group it by it.Due into g 
       select new Section (((DateTime) g.Key).ToString("d")) 
       { 
        from hs in g 
         select (Element) new StringElement (((DateTime) hs.Due).ToString("d"), 
          delegate 
          { 
           ItemPage itemPage = new ItemPage(this, hs); 
           itemPage.PushViewController(); 
          }) 
         { 
          Value = hs.Name 
         }              
       } 
     }; 

     if (dvc == null) 
     { 
      // create and push the dialog view onto the nav stack 
      dvc = new DialogViewController(UITableViewStyle.Plain, root); 
      dvc.NavigationItem.HidesBackButton = true; 
      dvc.Title = NSBundle.MainBundle.LocalizedString ("Calendar", "Calendar"); 
      this.PushViewController(dvc, false); 
     } 
     else 
     { 
      // refresh the dialog view controller with the new root 
      var oldroot = dvc.Root; 
      dvc.Root = root; 
      oldroot.Dispose(); 
      dvc.ReloadData(); 
     } 
     base.ViewDidAppear (animated); 
    } 
} 

回答

1

我想通了什麼事情。當內部DialogViewController(在ItemPage中創建)上按下後退按鈕時,外部DialogViewController(上面的「T1」)現在是第一響應者,而不是UINavigationController(「N1」)。我的困惑源於這個事實,即我在後面的按鈕關閉,因此我假設我已經彈出到UINavigationController(N1),而我仍然在DialogViewController(T1)。

我實現了所期望的行爲(清爽的「T1」的內容)創建(在這種情況下ItemPage)在內DialogViewController一個ViewDissapearing事件和檢查我是否彈出了 - 如果是這樣,調用父控制器的ViewDidAppear方法。

 actionsViewController.ViewDissapearing += (sender, e) => 
     { 
      if (actionsViewController.IsMovingFromParentViewController) 
       controller.ViewDidAppear(false); 
     }; 

注意這段代碼有趣的是,實際工作性質是IsMovingFromParentViewController,NOT IsMovingToParentViewController(這是什麼直覺你會覺得,當你回到原先將被設置)。我想這可能是MT.Dialog中的一個錯誤,但是出於回覆原因無法解決的問題。

我希望這會幫助別人......

相關問題