Search code examples
iosobjective-cswiftuinavigationcontroller

Pattern Navigation controller select controller - Swift


I have this scenario:

enter image description here

I have a navigation controller within a view controller with table view and varius cells. When cell is tapped, I go to another view controller (with "TEST" label text for testing).

My problem is this:

My app can be able to open from URL and in its query string there is a param that indicate which controller have to open (that with the table view or that with label).

I cant to find a pattern for to achive this in "clean" way.

For example:

I receive an URL with query param that indicate that I have to open the controller with label.

How can I organize the code to indicate that you must first go to the controller with the table and simulate the cell tap then go to the final controller?


Solution

  • Every navigation controller has array of view controllers. In case that you need to add both view controllers you can use next solution:

    NSMutableArray *controllers = [self.navigationController.viewControllers mutableCopy];
    [controllers addObject:tableVC];
    [controllers addObject:labelVC];
    [self.navigationController setViewControllers:controllers animated:YES];
    

    This will animate labelVC without the tableVc becoming visible in the process. When the user press the back button, he will be returned to the tableVC