ios - 想要两种方式到达 View Controller ,但只有一种方式返回

标签 ios objective-c storyboard

我正在制作一个 iOS 应用程序,用户可以在主菜单中启动该应用程序(见图)。

当用户单击 button1 时,它会触发一个 segue (1),将他带到配置向导。另一方面,单击按钮 2 会将用户带到配置列表(显示已设置的内容),这也使用了 segue (2)。这两个 View Controller 都有一个后退按钮,通过调用

将用户带回主菜单
[self dismissViewControllerAnimated:YES completion:nil];

我现在正在努力实现的是一种从配置向导过渡到配置列表的方法。

当用户在向导中做出选择并按下保存按钮时,我希望这会将他直接带到配置 ListView 。同时,向导 View Controller 应该被“遗忘”,即当用户现在按下后退按钮 2 时,它仍应将他带回主菜单。这意味着我不能只从向导触发到列表的 segue,因为那样向导仍然存在,在 ListView “后面”,并且在按下后退按钮 2 时会变得可见。

关于如何顺利实现这个的任何想法? storyboard

最佳答案

您可以从配置向导添加一个 segue 到配置列表。为避免返回配置向导,请存储主菜单 ViewController 指针并使用 popToViewController API 进行导航。

使用 popToViewController 的代码示例。

NSArray * controllerArray = [[self navigationController] viewControllers];

for (UIViewController *controller in controllerArray){
    //Code here.. e.g. print their titles to see the array setup;
    //NSLog(@"%@",controller.title);
    if ([controller.title isEqual:@"ViewTitle"]) {
        [self.navigationController popToViewController:controller animated:YES];
    }
}

希望这对您有所帮助。

关于ios - 想要两种方式到达 View Controller ,但只有一种方式返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23649292/

相关文章:

ios - 白名单 URL 方案解决方法

iOS - 关于 setAlpha 的导入与前向声明

ios - 使用 self 关键字时的困惑

ios - 虽然从一个 Storyboard解雇到另一个 Storyboard,但最近它很快就被解雇了

ios - 文本不适合特定字体的 UIButton titleLabel 高度

objective-c - 在 Objective-C 中监控当前的 dB 级别

ios - 设置所选 tableviewCell 背景颜色的框架在 iOS 7 中工作正常,但在 iOS 6 中不行

iOS 导航 View 背景图像 UIViewContentModeScaleAspectFill 不工作

ios - 在 UIImageView 和 UITableViewCell 之间添加 NSLayoutConstraint

objective-c - 你能通过 dismissModalViewControllerAnimated : or do you need a segue for the return journey? 返回数据吗