Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to push a viewController before dismissing modal view controller with Storyboards?

While trying out storyboards for one of my projects I came across something for which I don't have a good solution;

I have a navigation-based application which shows a UITableViewController. The tableView is populated with user-created elements. Tapping an element cell brings up the detail view controller. The user can create a new element by tapping a button in the tableView. This brings up a modal view, which will handle the creation.

Now, when a user is done with creating the element and dismisses the modal view controller, I want the user to see the corresponding new detail view controller and not the tableview. But I can't figure out how to achieve this in storyboards.

Does anyone have a good pattern for this?

Current situation

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

Should be

TableView --(tap create)--> creation modal view --(finish creating)--> detail view
like image 982
SpacyRicochet Avatar asked May 05 '13 09:05

SpacyRicochet


People also ask

How do you dismiss a modal view controller?

According to the View Controller Programming guide for iPhone OS, this is incorrect when it comes to dismissing modal view controllers you should use delegation. So before presenting your modal view make yourself the delegate and then call the delegate from the modal view controller to dismiss.

How do I remove a view controller from storyboard?

To delete the View Controller from the storyboard, select the View Controller by clicking the Show Document Outline icon and then clicking on View Controller Scene in the Document Outline. Then press Backspace or choose Edit > Delete.

How do you dismiss a storyboard?

Select the button that should make the UIViewController Disappear and drag it to the UIViewController you want to go to. In my case it shows **dismiss Controller* because of the name of my Class. Select it and you are done!


1 Answers

You can put the creating view controller in a navigation controller and link the creation view controller to the detail view controller as well with a push segue. When you finish creating the data it will direct to an instance of detail view controller.

If you want to navigate back from details view directly to the table view, you can add a property to the details view controller, say @property (nonatomic) BOOL cameFromCreationViewController;. You can set this property in prepareForSegue: in the source view controller. In the details view make your own back button, and when it's tapped, you can do this:

if(self.cameFromCreationViewController){
     [self.presentingViewController dismissViewController];
}
else {
     [self.navigationController popViewController]
}
like image 118
Mohannad A. Hassan Avatar answered Oct 04 '22 02:10

Mohannad A. Hassan