popViewControllerAnimated的断断续续的动画:来自alertView:didDismissWith



我在方法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 年以来,此代码在应用程序中一直保持不变,最近开始表现得很奇怪。

你可以尝试用willDismissWithButtonIndex而不是didDismissWithButtonIndex

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

对我来说,这项工作还行!,希望对您有所帮助

最新更新