gpt4 book ai didi

ios - UINavigationController 上的 ViewDidAppear 在向后导航时未被调用

转载 作者:行者123 更新时间:2023-11-29 13:37:30 25 4
gpt4 key购买 nike

我有一个 UITabBarController,它承载 5 个 UINavigationControllers(我们称它们为 N1 - N5)。每个 UINavigationControllers 都有导致 UITableViewController 被推送到导航堆栈的 UI 元素(我使用 MonoTouch.Dialog DialogViewController 来实现这些 UITableViewControllers)。我们称它们为 T1 - T5。

当我在选项卡之间导航时,ViewDidAppear 方法按预期在 N1 - N5 中的每一个上被调用。但是当我触摸一个 UI 元素时,比如 N1,这会导致 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);
}
}

最佳答案

我明白了这是怎么回事。当在内部 DialogViewController(在 ItemPage 中创建)上按下后退按钮时,外部 DialogViewController(上面的“T1”)现在是第一响应者,而不是 UINavigationController(“N1”)。我的困惑源于我关闭了那个外部 DialogViewController 上的后退按钮,所以我假设我一直弹出到 UINavigationController (N1),而我还在 DialogViewController (T1) 中。

我通过在内部 DialogViewController(本例中为 ItemPage)上创建一个 ViewDissapearing 事件并检查我是否实现了所需的行为(刷新“T1”的内容)弹出 - 如果是,则调用父 Controller 的 ViewDidAppear 方法。

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

请注意这段代码的有趣之处在于实际起作用的属性是 IsMovingFromParentViewController,而不是 IsMovingToParentViewController正在导航回来)。我想这可能是 MT.Dialog 中的一个错误,但由于后向紧凑的原因无法修复。

我希望这最终能帮助到某人...

关于ios - UINavigationController 上的 ViewDidAppear 在向后导航时未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10158960/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com