Perhaps you need to add your popup window as a child controller using addChildController
to the controller you show it from so that it is not detached from a view hierarchy?
Also you could try: Another option:
[self.parentViewController presentViewController:picker animated:YES completion:nil];
I noticed this on another thread as a solution. Warning :-Presenting view controllers on detached view controllers is discouraged
In your case, parentViewController may well be nil.
Edit After Seeing Code:
After looking at the code, the problem seems to be as follows:
1) The popup mechanism is using an instance of a UIViewController to create a layout, but you are not actually using the view controller at all. The popup mechanism (showInView:withImage:withMessage:animated:
) is extracting the view from the controller and adding it into the view hierarchy of the controller asking for the popup. So using code from this popup controller instance which calls [self presentViewController...]
is presenting a modal controller from a controller which is not actually being used. This is where the error is coming from I believe. You need to do all alerts and modal presentations from the original controller OR pass in the controller to use.
2) The original article mentions that because only the container view of the controller is used, you need to keep a strong reference to it when you create it. So you should have:
self.popViewController = [[PopUpViewController alloc] initWithNibName:@"PopUpViewController" bundle:nil];
Solution:
I would extend the showInView...
method to pass in the controller which owns the view the popup is being spliced into. Then use this controller to present any modal controllers. So change:
- (void)showInView:(UIView *)aView withImage:(UIImage *)image withMessage:(NSString *)message animated:(BOOL)animated
to
- (void)showInController:(UIViewController *)aController inView:(UIView *)aView withImage:(UIImage *)image withMessage:(NSString *)message animated:(BOOL)animated
Store the controller reference passed in a property in your PopUpViewController
class then use this property to call presentViewController...