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

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;
}];

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})

Dissmiss modal controller triggered Segue in Swift/Objc hybrid project

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.

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.

After modal view controller dismissed any pushed controller doesn't call viewDidAppear

I use
this.PresentViewController(...);
to display a modal view controller another controller.
Then on dismiss button action inside the modal view controller I call
this.DismissViewController(...);
The problem is in that application stops calling viewDidAppear methods in every other controller inside of my NavigationController until I reinitialize it. Actually the problem appears only on iPhone (iOS 5/6).
How to bring application to life after dismissing a modal view?

Dismiss Modal NavigationController from pushed ViewController inside

I have an iPad app and I'm using the storyboard. I'm presenting a modal view, which I wrap in a UINavigationController. It's a modal "Settings" view with it's own navigation.
I have a delegate setup to dismiss the modal view itself with a Done button in the Settings view which works fine, but I need to be able to dismiss it even after it has pushed another view when the user taps a setting.
So, basically a "cancel" button on the right side of the Navigation bar in the pushed views.
Instead of having to go back to the first "Settings" view to hit the done button.
I've tried setting up a second delegate for the pushed view without success:
Just add a bar button item and put this line in its action method:
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
The presenting view controller will be the controller that presented the modal, not the navigation controller.

Resources