我有一個UITabBarController
,它承載5個UINavigationControllers
(我們稱之爲N1-N5)。 UINavigationControllers
中的每個UI元素都會導致UITableViewController被推送到導航堆棧上(我使用MonoTouch.Dialog
DialogViewController
來實現這些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);
}
}