【发布时间】:2016-06-13 16:49:15
【问题描述】:
当在 UIalertView 委托方法 alertView:didDismissWithButtonIndex: 中完成时,我遇到了方法 popViewControllerAnimated: 中的动画问题。它不稳定且快速(使用 Xcode 7.3.1)。谁能明白为什么?
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alertView.cancelButtonIndex)
{
// animation of popViewControllerAnimated: is not working correctly
[self.navigationController popViewControllerAnimated:YES];
}
}
奇怪的是这段代码没有问题:
- (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];
});
}
}
}
还有这个:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex != alertView.cancelButtonIndex)
{
// no problem with animation when done in alertView:clickedButtonAtIndex:
[self.navigationController popViewControllerAnimated:YES];
}
}
我知道UIAlertView 已经被弃用了一段时间,是不是因为这个?自 2012 年以来,此代码在应用程序中一直未触及,最近开始表现得很奇怪。
【问题讨论】:
标签: ios grand-central-dispatch uialertview popviewcontrolleranimated