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?
Related
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})
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;
}];
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.
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.
I am developing an iPad application using storyboard. In my application I have connected one modal view controller from first view controller using segue modal presentation for fetching some data. Modal view controller is closed by clicking on the cancel button in the modal view. Cancel button and first view controller are connected by using a modal segue. In first view controller I have a table view and I added some values to the tableview using a button. But my problem is if go to modal view then return back to my first view controller the table view in the first view controller is reloaded and I lost the result in the tableview. How do I prevent the data reload in the table view when the modal view is dismissed on pressing cancel.
These two points may solve your issue
Don't give [table reload] in ViewWillAppear or ViewDidAppear
Make sure viewDidLoad is not getting called when view is returned from modal View