Is it possible, on the basis of this scheme, making the transitions 1 -> 2 -> 3 -> 5 , or 1 -> 2 -> 3 -> 4 -> 5 , to be able, while in окне 5 , to return (three buttons below окна 5 ) into the same stack 1 -> 2 into the open окно 2 and reload it with the updated passed parameters. So that in this окне 2 when you click on the back again to return to the same stack in окно 1 ?

enter image description here

I know that there is a way to return the stack to window 2, but how, in that case, can I pass the parameters I need? Or does this solution prevent them from being transmitted?

 UIViewController *prevVC = [self.navigationController.viewControllers objectAtIndex:1]; [self.navigationController popToViewController:prevVC animated:YES]; 

ADDED: How out of 5 windows when the transition is 1 -> 5 , make the transition 5 -> 1 -> 2 ?

  • you have already answered the question of how to return, and how to transfer the parameters - for this you have a model (and if not, be sure to create it :)) - Max Mikheyenko
  • Did not quite understand what is meant by "model"? Temporarily made through NSUserDefaults :) works, but I am looking for a more practical way. - Chekist 2:41 pm
  • the model is the 'M' of MVC :) in short, some kind of data storage with which the application operates. It can be a class / set of classes, a database, and so on. NSUserDefaults can actually be used as a model, but its direct responsibility is data storage between sessions. - Max Mikheyenko

1 answer 1

Here you just need to find a way to transfer data, Cocoa does not provide a ready-made solution, but you can solve the problem head-on with the help of banal programming and an object-oriented approach. You have a stack of view controllers, you need to pull out a specific object from it and set the required fields for it. for example

 CustomViewController *callbackController = (CustomViewController *)self.navigationController.viewControllers[2]; callbackController.callbackProperty = callbackObject; 

This solution is a bit of a crutch, because it requires a well-defined navigation stack. You can also take an indent from the current instead of a specific position, for example

 CustomViewController *callbackController = (CustomViewController *)self.navigationController.viewControllers[[self.navigationController.viewControllers indexOfObject:self] - 2]; 

But it's still a crutch.


Another option is to send data to the desired controller by notification (read about NSNotificationCenter ). But again, a thin spot - the notification should be caught by only one object, and if there are several of them - how to determine the recipient? I suppose that the storyboard may have some mechanisms for returning data from a segui, but I have never worked with this.


And now the most correct answer - the controller when pushing other controllers must pass them the object responsible for returning data - this can be a block, a delegate or a changeable object in which in the future another controller will put the data before the "pop". Most likely the last option is what you need, for passing a block / delegate through a few push-ins is a bad tone, but the object of return is the most it.

An example is a document object, it has a header. The main counternoller is the one in which the document is simply viewed, click on the edit button - the document already transferred to the editing controller. There, the button "Edit title" is acquired and the object went to the header input controller. There, the user enters a new header, clicks Done, and before the "pop" in the document.title , the value from the text field is written.