Completion block for popViewController
I know an answer has been accepted over two years ago, however this answer is incomplete.
There is no way to do what you're wanting out-of-the-box
This is technically correct because the UINavigationController
API doesn't offer any options for this. However by using the CoreAnimation framework it's possible to add a completion block to the underlying animation:
[CATransaction begin];
[CATransaction setCompletionBlock:^{
// handle completion here
}];
[self.navigationController popViewControllerAnimated:YES];
[CATransaction commit];
The completion block will be called as soon as the animation used by popViewControllerAnimated:
ends. This functionality has been available since iOS 4.
How to detect pop/push animation ended within a navigationController
UINavigationControllerDelegate
func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
}
func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
}
How to push a view controller safely from a completion block?
Try something like:
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if (self.navigationController.topViewController == self) {
Model *model = [[Model alloc] initWithPFObject:[objects objectAtIndex:0]];
controller.annotation = model;
[self.navigationController pushViewController:controller animated:YES];
}
}];
This way it won't push if you already have another view controller on top of self
. And also make sure that you are doing all this on the main thread.
While an existing transition or presentation is occurring; the navigation stack will not be updated
This warning indicates that you are trying use UINavigationController
wrongly:
pushViewController:animated: called on while an existing transition or presentation is occurring; the navigation stack will not be updated
You mentioned in the comments that you are trying to pop
theViewController
using
navigationController?.popViewControllerAnimated(false)
inside completion block of UIAlertController
. Therefore, you are trying to unwind from the wrong view, UIAlertController
is not part of the UINavigationController
stack.
Try and close the UIAlertController
first, then pop the current ViewController
. In other words, remove the pop
from the completion
block and put it inside the OK
block. or use unwind
segue before the alert.
Another possibility, is that you have an unused or identical duplicate in storyboard
. Hence, if the unwinding
operation is triggered by storyboard
button, select this button and check the connectivity inspector
and removed unwanted connections.
For example: the red x marked was unnecessary in my case.
Related Topics
How to Put a Logo in Navigationview in Swiftui
Specifying One Dimension of Cells in Uicollectionview Using Auto Layout
How to Batch Request with Afnetworking 2
Scale Image in an Uibutton to Aspectfit
Setneedslayout and Setneedsdisplay
Wireless iPhone App Distribution - Problem with Itms-Services Protocol
Debug on Real Apple Watch: Application Verification Failed
Programmatically Select All Text in Uitextfield
Why Is Uiscrollview Leaving Space on Top and Does Not Scroll to the Bottom
How to Limit an iOS App Only to 4 Inch Screen Devices
Implementing Fast and Efficient Core Data Import on iOS 5
iPhone Simulator Suddenly Started Running Very Slow
iOS Convert Large Numbers to Smaller Format
How Is the Relation Between Uiview's Clipstobounds and Calayer's Maskstobounds
Converting Utc Date Format to Local Nsdate