0

在委托方法popViewControllerAnimated:中完成时,我遇到了方法中的动画问题。它断断续续且速度很快(使用 Xcode 7.3.1)。谁能明白为什么?UIalertViewalertView:didDismissWithButtonIndex:

- (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 年以来,此代码在应用程序中一直未触及,最近开始表现得很奇怪。

4

1 回答 1

1

您可以尝试使用willDismissWithButtonIndex而不是didDismissWithButtonIndex

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != alertView.cancelButtonIndex)
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

对我来说,这项工作没问题!,我希望这对你有帮助

于 2016-06-13T20:59:50.607 回答