ios - 如何在按下后退按钮时跳过上一个 View

标签 ios swift model-view-controller uinavigationcontroller

我的导航是:

List of Friends with messages Controller(点击撰写)-> List of friends to select chatting(选择 friend )-> Show chat with friend

目前,如果在 Show chat with friend 中,用户选择 back,它会将他们带到 List of friends 以选择聊天 Controller 。 我想跳过这个 Controller ,并在返回选择时导航到 List of Friends with messages Controller

注意:List of Friends with messages Controller 嵌入在选项卡中。

我尝试使用:self.navigationController?.viewControllers.removeLast(),在选择聊天的 friend 列表之间的segue中> 将其从堆栈中移除。但是在导航到 Show chat with friend 之后,后退按钮消失了......

如何允许我描述的导航?

最佳答案

如果您的目标是跳过第二个 UIViewController 并从第三个 UIViewController 返回到第一个 UIViewController。试试下面的代码:

// This count will return how many view controllers are there in navigation stack
let controllersInNavigationCount = self.navigationController?.viewControllers.count

// This will pop to first UIViewController skipping second UIViewController
self.navigationController?.popToViewController(self.navigationController?.viewControllers[controllersInNavigationCount!-2] as! FirstViewController, animated: true)

关于ios - 如何在按下后退按钮时跳过上一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37636393/

相关文章:

iOS 6 应用内购买 - 无需使用需要用户密码的 'restoreCompletedTransactions' 即可访问已完成的交易数据

ios - 延迟激活 uitableviewcell 内的 uislider 的时间

swift - 将带图像的富文本存储到 Core Data 的最佳方法?

asp.net-mvc - MVC中的业务规则在哪里

model-view-controller - 使用 Orchard CMS 的计划任务

ios - 如何调试带有附件的 IOS 应用程序

android - 在firebase,flutter中应该如何处理好友请求和邀请?

ios - 如何在 Interstitial 被解散之前释放场景?

arrays - 使用枚举查找数组(Swift 5)中的所有组合

javascript - 如何从 MVC 在 Highcharts 中添加系列数据