編集
数週間前に別の同様の問題を思い出しました。競合状態が発生していますが、おそらくGCD (Grand Central Dispatch) を使用して解決できます。これは @rakeshNS が提案したソリューションに似ていますが、危険性は低くなります。(競合状態を処理するためにタイマーを使用することは悪い習慣ですが、多くの言語では、0 秒のタイマー待機でメソッドを呼び出すことは、そのメソッド呼び出しを呼び出しスタックの最後に配置するために使用されるトリックです。つまり、非同期にします)。Apple は、このためのメカニズムを提供しています。
私はこのわずかな編集を試みます:
[customAlertLoad dismissViewControllerAnimated:NO completion:^{
dispatch_async(dispatch_get_main_queue(), ^(void) {
CustomAlertMsg *cust = [[CustomAlertMsg alloc] init];
cust.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
cust.modalPresentationStyle = UIModalPresentationFormSheet;
cust.delegate = self;
[self.navigationController presentModalViewController:cust animated:YES];
cust.view.superview.frame = CGRectMake(0, 0, 458, 230);
cust.view.superview.center = self.view.center;
});
}];
dispatch_async を呼び出すと、ブロックが実行スタックの最後に置かれます。モーダルが閉じられる前にこれを実行する方法はありません。これにより、2 つのモーダルの却下と表示のアニメーションも可能になります。
ただし、この特定の問題では、これはハックであることに言及する必要があります。 別の場所で問題が発生しています。テスト プロジェクトでセットアップを再現すると、エラーが発生することなく、完了ブロックから必要な数のモーダルを作成/破棄できます (モーダルを破棄するために使用されるカスタム デリゲート コールバックから破棄コードが呼び出されている限り)。 、アップルが示唆するように)。カスタム アラートの負荷とカスタム アラート クラスのコードを調べます。
編集を終了
これはあなたの問題とは異なる場合があります。コードベースを ARC に移動した後、ポップオーバーでこの問題が発生したことがあります。Popover のリリースが早すぎたり、保持が長すぎたりすると、奇妙なことが起こりました。解決策は、インスタンス変数を作成してポップオーバーを保持し、手動で nil することでした。その後、すべてがホンキードーリーで機能し始めました。
だから私はするだろう:
@interface YourClass:UIViewController
@property (nonatomic,strong) CustomAlertMsg *cust;
@end
@implementation YourClass
... Codey Code....
-(void)pushView{
// For the sake of sanity, nil the modal here
if(self.cust != nil) self.cust = nil;
self.cust = [[CustomAlertMsg alloc] init];
self.cust.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
self.cust.modalPresentationStyle = UIModalPresentationFormSheet;
self.cust.delegate = self;
[self.navigationController presentModalViewController:self.cust animated:YES];
self.cust.view.superview.frame = CGRectMake(0, 0, 458, 230);
self.cust.view.superview.center = self.view.center;
}
// Then where you dismiss it, or in the delegate callback that is
// called when you dismiss it, if you are using one anyway,
// nil it out
- (void)methodThatDismissesModal
{
[self dismissModalViewControllerAnimated:YES];
// This is pretty important
if(self.cust != nil) self.cust = nil;
}
... Codey Code....
@end