change
I recalled another similar problem a few weeks ago. You are experiencing a race condition that can probably be solved with GCD (Grand Central Dispatch). This is similar to @rakeshNS solution, but less dangerous. (Using timers is bad practice for handling race conditions, although in many languages ββcalling a method with a 0 second timer is a trick used to call this method at the end of the call stack, which also made it asynchronous). Apple provides a mechanism for this.
I would try to make this small change:
[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; }); }];
The dispatch_async call puts the block at the end of the execution stack. It is not possible to run this before the modal version is fired. It also allows animation when firing and presenting two modals.
However, I must mention that in this particular problem it is a hack. You have a problem somewhere else . If I reproduce your installation in a test project, I can create / fire as many modals from completion blocks as possible without running into your error (as long as the reject code is called from the delegate custom callback used to reject the modal, as the apple says ) I would look at your custom alert download and custom alert code.
end edit
It may not be the same as your problem, I ran into this problem before popovers appeared after moving my code base to ARC. There were strange things when my Popover was released too soon or too long. The solution was to create an instance variable to hold Popover and manage it manually. Then it all started with honkey dory.
So, I would do:
@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