How to click viewController before rejecting a modal view controller using storyboard?

Having tried the storyboards for one of my projects, I came across something for which I do not have a good solution;

I have a navigation based application that shows a UITableViewController. TableView is populated with custom elements. Clicking on a unit cell calls up the detail view controller. The user can create a new item by clicking a button in the View table. This invokes a modal representation that the creation will handle.

Now that the user has completed the creation of the element and rejected the modal view controller, I want the user to see the corresponding new controller for the detailed view, not the tableview. But I can’t figure out how to achieve this in storyboards.

Does anyone have a good template for this?

Current situation

TableView --(tap create)--> creation modal view --(finish creating)--> TableView 

Must be

 TableView --(tap create)--> creation modal view --(finish creating)--> detail view 
+6
source share
2 answers

The best sample I could come up with is the same as the old template in the code.

Add the (nonatomic, weak) UINavigationController *sourceNavigationController to the modal view controller. When the time comes to reject the modal view controller, add the following code:

 DetailViewController *detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"]; detailViewController.element = newlyCreatedElement; [[self sourceNavigationController] pushViewController:detailViewController animated:NO]; 

And to make sure the sourceNavigationController parameter sourceNavigationController set correctly, add the following code to prepareForSegue: TableView:

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([segue.identifier isEqualToString:@"newElementSegue"]) { [[segue destinationViewController] setSourceNavigationController:self.navigationController]; } } 
0
source

You can put the creating view controller in the navigation controller and associate the creation view controller with the detailed view controller, as well as using the push segment. When you are finished creating the data, it will be redirected to the instance of the detail view manager.

If you want to go from viewing parts directly to a table view, you can add a property to the part view controller, say @property (nonatomic) BOOL cameFromCreationViewController; . You can set this property in prepareForSegue: in the source view controller. In the detail view, make your own back button, and when you click it, you can do this:

 if(self.cameFromCreationViewController){ [self.presentingViewController dismissViewController]; } else { [self.navigationController popViewController] } 
+1
source

Source: https://habr.com/ru/post/944306/


All Articles