6

UIViewControllモーダルとして表示される2つを作成しました。最初の 5 回の試行では、モーダルは正常に表示されますが、その後は次のようになります。

Warning: Attempt to dismiss from view controller <UINavigationController: 0x76a8450> while a presentation or dismiss is in progress!

以下は、現在のView Controllerを閉じて別のView Controllerを表示するためのコードです

[customAlertLoad dismissViewControllerAnimated:NO completion:^{ 
     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;
}];

どんな助けでも大歓迎です。

4

5 に答える 5

2

編集

数週間前に別の同様の問題を思い出しました。競合状態が発生していますが、おそらく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
于 2013-02-25T21:22:54.603 に答える
2

エラーメッセージが示すように、問題は却下中に現れます。presentModalViewControllerトラブルの原因は ではなく、dismissViewControllerAnimatedです。

その通話のコンテキストを貼り付けていただければ、解決策が見つかるかもしれません。

于 2013-02-22T09:29:07.367 に答える
1

これに変更してみてください:

[self.navigationController presentModalViewController:cust animated:NO];
于 2013-02-21T16:48:36.083 に答える
1

おそらく、代わりにナビコントローラーから閉じてみてくださいcustomAlertLoad

[self.navigationController dismissViewControllerAnimated:NO completion:^{

    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;

}];
于 2013-02-21T16:54:39.307 に答える