0

时,它的UIalertView委托方法内部完成alertView:didDismissWithButtonIndex:这是波涛汹涌和快速(使用的Xcode 7.3.1)我在与方法popViewControllerAnimated:动画问题。任何人都能明白为什么popViewControllerAnimated的波涛汹涌的动画:从alertView: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年以来一直未在应用程序中使用,最近开始表现得很奇怪。

回答

1

您可以用willDismissWithButtonIndex代替didDismissWithButtonIndex

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

对于我这种工作确定尝试!我希望这可以帮助你

+0

是,由于它的工作原理:)除了'clickedButtonAtIndex:'我在问题中写道。但是我仍然对“didDismissWithButtonIndex:”的问题感到困惑。 – turingtested

相关问题