我在popViewControllerAnimated:
委托方法UIalertView
中完成时,方法alertView:didDismissWithButtonIndex:
中的动画有问题。它不稳定且速度快(使用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年以来,该代码在应用程序中未受影响,并且最近开始表现得很奇怪。
答案 0 :(得分:1)
您可以尝试使用willDismissWithButtonIndex
代替didDismissWithButtonIndex
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (buttonIndex != alertView.cancelButtonIndex)
{
[self.navigationController popViewControllerAnimated:YES];
}
}
对我来说这项工作还好!我希望这可以帮到你