我有一个UITabBarController
主机 5 UINavigationControllers
(我们称它们为 N1 - N5)。每个UINavigationControllers
都有 UI 元素,这些元素会导致 UITableViewController 被推送到导航堆栈(我MonoTouch.Dialog
DialogViewController
用来实现这些UITableViewControllers
)。让我们称它们为 T1 - T5。
当我在选项卡之间导航时,该ViewDidAppear
方法会按预期在每个 N1 - N5 上调用。但是当我在 N1 上触摸一个 UI 元素时,这会导致 T1 被推入导航堆栈,然后尝试使用后退按钮返回,N1 的ViewDidAppear
方法不会被调用。
有趣的是,如果我“切换”到不同的选项卡(比如 N2),然后“切换回”到 N1,ViewDidAppear
则会正常调用。即使我将 T1 推到导航堆栈上,如果我执行相同的选项卡,N1ViewDidAppear
仍然会被调用。
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);
}
}