Dissmiss modal controller triggered Segue in Swift/Objc hybrid project - ios

I have a situation that I'm not sure how to handle correctly. As you see in the picture below I have a Table View Controller, I have a Modal Popup and another View Controller.
What I'm trying to do is when the user clicks a button on the left most TableView controller a pop up will display via a Modal Segue. Once dismissed the the Navigation Controller will transfer to the Right ViewController
Initial View Controller
* Button Pressed Segue Modal
Swift Modal Controller
* Presses button and calls self.dismissViewControlelr
But then what happens?

If I understand correctly, you'd like to have the navigation controller perform a push segue after a presented view controller dismisses itself.
There are a couple ways to go about it, but I think simplest is to have the presented view controller (the "swift modal") post a notification from within the completion block of the dismiss function.
The vc contained by the navigation controller should then perform the push segue upon receiving this notification.

Related

Dismiss all modals in iOS with Swift 4

I am trying to achieve a navigation similar to the Netflix app for iOS. When you click on a movie, a modal window pops up with a close button. If within this movie I choose to see another movie then the second modal pops up and in addition to the close button, a back button appears. I can use the back button to dismiss one by one and the close button to return to the base screen.
I am able to dismiss a single view using
dismiss(animated: true, completion: nil)
but how can I return to the base screen closing all modals at once? Also, is modals the way to go? I chose this because I didn't want the navigation bar on top.
I'm working with Swift 4.2 in Xcode 10.
The way you are dismissing a ViewController is not the correct way. The presenting view controller is responsible for dismissing the view controller. Ideally you have to implement a protocol in your presenting ViewController and , dismiss your modal from your 'presenting' ViewController not 'presented' ViewController.
The reason why your way still works is, when a ViewController calls self.dimiss if there's nothing to dismiss UIKit will delegate it back to its parent. If you implement this correct way, once you dismiss , your presenting viewcontroller will dismiss , hence all the presented viewcontrollers will be dismissed instead of the last one.
From Apple Docs:
The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, UIKit asks the presenting view controller to handle the dismissal.
If you present several view controllers in succession, thus building a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.
If you want to retain a reference to the view controller's presented view controller, get the value in the presentedViewController property before calling this method.
The completion handler is called after the viewDidDisappear(_:) method is called on the presented view controller.
try this
self.navigationController?.viewControllers.removeAll(where: {$0.isModalInPopover})

How to transition to root view controller without navigationController?

I have an application that transitions from the main launchVC to a register or login VC and then from there transitions into the main application view controller. Now I am not using the built in navigation that you can use with an iOS app instead I'm using my own buttons. So my question is how do I "pop back" to the launchVC. Image in application where you have logged in and when you tap "log out" all of the view controller get dismissed back to the launch view controller. Any help would be appreciated. Thank you!
You can make your launch view controller a delegate, passing it to the view controller that contains the logout button. Once the button is pressed, then that will notify the delegate (launch view controller) which can then dismiss all of the presented view controllers.
Here is a tutorial on how to configure such a pattern.

warning attempt to dismiss from view controller while a presentation or dismiss is in progress

Steps to reproduce -
Open Modal view controller on tap of button of Root View controller.
In Modal view controller - On button, create segue to show popover view controller.
Tap on button to see Popover view controller.
Now multiple taps on screen to dismiss the popover view controller, it directly redirects to Rootview controller.(dismissing the Modal view controller).
Another approach -
Create IBAction to show popover view controller.
Tap on button to see Popover view controller.
This time it just dismiss the pop view controller. (Not redirecting to RootView controller)
Why this weird behavior when your showing Popover view controller in two different ways?
I am working on already developed big project and now its not possible for me to go ahead with second approach.
Please help me to find out the better way to resolve this.
You will need to create a delegate method in your Modal view controller.
After your popover view controller dismissed, then call your Modal view controller delegate method to dismiss as well.
[self dismissViewControllerAnimated:YES completion:^{
ModalViewControllerDelegate.dismissView;
}];

iOS - navigation controller back button

I'm developing an iPad App using storyboards. In this app when the user click on "preferences" appear a modal View. One button of this view send the user to another View Controller (but this view has an action bar to go back to his root view controller), but when user taps the action bar back button nothing happen (it's called navigationController popViewControllerAnimated), the user continue in the same view.
Can anyone help me??
Thanks.
UPDATE:
The code to handle the back button:
- (IBAction)btnBackTapped:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
I'm using Segue (from storyboard) to call this View Controller:
When the user click on "Meus Favoritos"
They will be redirect to this page:
The segue is with a Modal (from image one to two)...
When you are presenting a View Controller modally, it is likely not within a Navigation Controller, so probably the reference to navigationController in your code is nil, can you check that?
If you are presenting your View Controller modally this will work instead
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
However, if you actually want to use a Navigation Controller, you should embed the View Controller that is presenting the Preferences View Controller in a Navigation Controller and present the Preferences View Controller with a show segue instead of a modal one.

In iOS < 6.0 how to go back after a push segue? And how to pass data from the second to the first view controller?

I have two view controllers inside a Navigation Controller.
First view controller calls, with a push segue, second view controller.
In second view controller I have a UIDatePicker and a "Ok" button.
I need that when i press Ok button:
I go back to my first view controller.
I pass the NSDate to it.
How can I do it on iOS<6.0? Unwind segues are not available.

Resources