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年以來一直未在應用程序中使用,最近開始表現得很奇怪。
是,由於它的工作原理:)除了'clickedButtonAtIndex:'我在問題中寫道。但是我仍然對「didDismissWithButtonIndex:」的問題感到困惑。 – turingtested