Jack
Jack

Reputation: 81

What happens if I dont Unwind a Segue in iOS?

I've an app where there are more than 10 ViewControllers and there is a MenuViewController Which is triggered by all the ViewControllers. And MenuViewController Triggers all ViewControllers. So in app I will not unwind a Segue but keep on triggering the segues.

Scheme:

Scheme

Does it give any side effect like out of memory or app hanging kind of? Will it be fine if I keep on triggering segues without unwinding them?

Somebody Please Help ???

Upvotes: 1

Views: 47

Answers (1)

Jack
Jack

Reputation: 81

You'll eventually run out of memory if you keep pushing new view controllers on the navigation stack without removing the previous ones. If you never want to pop back to a previous view controller, you can remove the complete navigation history after the push transition has finished in each view controllers viewDidAppear::

- (void)viewDidAppear {
    [super viewDidAppear];
    self.navigationController.viewControllers = @[self];
}

Alternatively, you can put this logic in a central place by setting your navigation controller's delegate and implementing navigationController:didShowViewController:animated::

- (void)navigationController:(UINavigationController *)navigationController
       didShowViewController:(UIViewController *)viewController
                    animated:(BOOL)animated {
    navigationController.viewControllers = @[navigationController.viewControllers.lastObject];
}

Upvotes: 1

Related Questions