首页 > 解决方案 > 如何正确导航 Xamarin.ios 中的导航堆栈?

问题描述

我目前正在开发 Xamarin.iOS 中的一个项目,但我不知道堆栈系统是如何工作的。

我有一个菜单,我可以在其中选择我的应用程序的语言,当我选择不同的语言时,我想动态刷新所有先前页面上的语言。

当我在我的语言设置中点击上一个按钮时,上一页没有翻译所以我决定创建一个新ViewController的,我把它放在堆栈的顶部this.NavigationController.PushViewController(new ViewController(), true)

但我认为这不是最好的方法,所以我尝试了

this.NavigationController.PopToRootViewController(true)有根ViewController,但有没有办法只获得堆栈上的上一页?

public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
{
    var cell = this.GetCell(tableView, indexPath);

    cell.SelectionStyle = UITableViewCellSelectionStyle.None;

    var previousIndexPath = NSIndexPath.FromRowSection(this.selectedIndex, 0);

    this.selectedIndex = indexPath.Row;

    var selectedLanguage = this.supportedCultures[this.selectedIndex];

    Localization.Culture = selectedLanguage;

    this.SaveLanguageToUserDefault(selectedLanguage);

    this.TableView.ReloadRows(new NSIndexPath[] { previousIndexPath,indexPath }, UITableViewRowAnimation.None);


    this.NavigationController.PopToRootViewController(true); 

    //this.NavigationController.PushViewController(new ViewController(), true);

}

标签: objective-cxamarinxamarin.ios

解决方案


在 iOS 中,如果您使用的是NavigationController,并且想要导航到上一个 ViewController,则可以使用 NavigationProperty 中的PopViewController方法。

this.NavigationController.PopViewController(true);

这将使您的应用程序关闭当前页面并显示上一个页面。

看,这与PopToRootViewController.

希望这可以帮助。-


推荐阅读