简体   繁体   English

在没有Segue的情况下在UIViewControllers之间移动

[英]Moving between UIViewControllers without Segue

I have a storyboard that has 8 UIViewController s on it (and counting). 我有一个故事板,上面有8个UIViewController (并且正在计数)。 I need to be able to move between any pair of these on demand. 我需要能够按需在任何一对之间移动。 Essentially, what I am trying to do is to mimic the functionality of a UITabBarController . 基本上,我想要做的是模仿UITabBarController的功能。 Since there are so many of these, I can't just use the UITabBarController (that would solve my problem immediately), so I am using a UIPopoverController with an embedded UITableView to allow the user to choose their destination. 由于有这么多,我不能只使用UITabBarController (这将立即解决我的问题),所以我使用UIPopoverController与嵌入式UITableView允许用户选择他们的目的地。

Of course, I could create segues on the storyboard, but to set up all of the segues that I need currently, I would have to create 56 such segues just for the view controllers that I have right now, and potentially many more as things grow. 当然,我可以在故事板上创建segue,但是为了设置我目前需要的所有segue,我将不得不为我现在拥有的视图控制器创建56个这样的segue,并且随着事物的增长可能会有更多。

One idea that I had was to create a 'hub' view controller that doesn't really do anything other than to hold the segues to each of the 'real' VCs and be the delegate of each of those VCs. 我的一个想法是创建一个“中心”视图控制器,除了将每个“实际”VC保持segue并成为每个VC的代表之外,它实际上并没有做任何事情。 Then, when I want to switch between VCs, I first dismiss the view controller and pass the segue name for the destination back to the hub. 然后,当我想在VC之间切换时,我首先关闭视图控制器并将目标的segue名称传递回集线器。 The hub can then immediately perform that segue, which gets me where I want. 然后集线器可以立即执行该segue,这可以让我到达我想要的位置。 I think that this would work, but is seems sort of hackish. 我认为这会起作用,但似乎有点像黑客。

Does anyone know how if there is a better way to accomplish this? 有谁知道如果有更好的方法来实现这一目标? Thank you! 谢谢!

Why don't you give each one a storyboard identifier, then grab anyone you need with its identifier using this: 为什么不为每个人提供一个故事板标识符,然后使用以下标识获取您需要的任何人的标识符:

UIViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"identifier"];

Then present this view controller via push or present modally 然后通过push或present模式呈现此视图控制器

You can easily do this with performSegueWithIdentifier: 您可以使用performSegueWithIdentifier:轻松完成此操作performSegueWithIdentifier:

[self performSegueWithIdentifier:@"myCustomSegue" sender:self];

And then in the prepareForSegue: method, configure what you need to: 然后在prepareForSegue:方法中,配置您需要的内容:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"myCustomSegue"]) {
        MyCustomViewController *customViewController = segue.destinationViewController;
        customViewController.customAttribute = @"something";
    }
}

You can also use shouldPerformSegueWithIdentifier: to control navigation. 您还可以使用shouldPerformSegueWithIdentifier:来控制导航。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 两个人像UIViewController之间的横向景观 - Landscape Segue Between Two Portrait UIViewControllers 在来自第三个UIViewController的两个UIViewController之间执行搜索 - Perform a segue between two UIViewControllers from third UIViewController 没有导航控制器的UIViewController之间的过渡 - transition between UIViewControllers without navigation controller 在UIViewControllers之间滚动而不丢失最后一个状态 - Scroll between UIViewControllers without losing last state 在没有导航控制器的情节提要中的UIViewControllers之间切换 - Switch between UIViewControllers in storyboard without Navigation Controller 如何在UIViewControllers之间传递数据而不显示它 - How to pass data between UIViewControllers without presenting it 在2个UIViewControllers之间移动,每个UIViewControllers具有1个UIView-XCode5 osx - moving between 2 UIViewControllers each with 1 UIView - XCode5 osx 自定义Segue Pushing / Popping UIViewControllers - Custom Segue Pushing/Popping UIViewControllers Swift UIViewController到另一个UIViewControllers(segue) - Swift UIViewController to another UIViewControllers (segue) 在两个UIViewControllers之间调用segue时,屏幕需要从右向左滑动 - When a segue is called between two UIViewControllers screen needs to slide from right to left
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM