I'm having problem with the animation in the method popViewControllerAnimated: when it's done inside the UIalertView delegate method alertView:didDismissWithButtonIndex: It's choppy and to fast (using Xcode 7.3.1). Can anyone understand why?
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alertView.cancelButtonIndex)
{
// animation of popViewControllerAnimated: is not working correctly
[self.navigationController popViewControllerAnimated:YES];
}
}
The strange thing is that this code works without problems:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alertView.cancelButtonIndex)
{
// code is running om main thread
if ([[NSThread currentThread]isMainThread]) {
// still - by using GCD and go to main thread, the animation works!!
dispatch_async(dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
}
}
}
And this:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex != alertView.cancelButtonIndex)
{
// no problem with animation when done in alertView:clickedButtonAtIndex:
[self.navigationController popViewControllerAnimated:YES];
}
}
I know that the UIAlertView has been deprecated for a while, can it be because of that? This code has been untouched in the app since 2012 and recently started to behave strange.
you can try with
willDismissWithButtonIndexinstead ofdidDismissWithButtonIndexfor me this work ok!, I hope this helps you