objective-c - 如何正确导航 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);
}
解决方案
在 iOS 中,如果您使用的是NavigationController,并且想要导航到上一个 ViewController,则可以使用 NavigationProperty 中的PopViewController方法。
this.NavigationController.PopViewController(true);
这将使您的应用程序关闭当前页面并显示上一个页面。
看,这与PopToRootViewController
.
希望这可以帮助。-
推荐阅读
- probability - 如何定义概率分布
- opengl-es - 如何根据与相机的距离将颜色与背景混合
- bash - 使用带有 ipython 的 jupyter 与 R (irkernel) 的 bash 的区别
- javascript - Angular 4+ 创建半圆形导航菜单,模块化与全局 CSS
- angular - 导入在ngrx中实现的模块并通过覆盖服务重用效果
- php - 无法在 WAMP 中执行 php 代码
- puppet - 安装一个手工制作的木偶模块在 Debian 伸展中发生了变化
- java - Java中的行间延迟
- javascript - Babel 的语法插件导致 Vetur 错误地报告错误
- android - Android 约束布局不工作/不响应