1

I hope someone can help me with this weird bug. I've got a popover with buttons to perform various actions. There is a toolbar item that must be clicked to bring up the popover. Here is the action method that is called:

-(IBAction)showActions:(id)sender
{
  ActionsPopUpController* controller = [[ActionsPopUpController alloc] initWithDelegate:self state:DELETE_ENABLED | FACEBOOK_ENABLED | TWITTER_ENABLED | EMAIL_ENABLED];
  _actionsPopUp = [[UIPopoverController alloc] initWithContentViewController:controller];
  [controller release];
  [_actionsPopUp presentPopoverFromRect:_actionButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
  _actionsPopUp.delegate = self;
}

As you can see, I have a property/ivar (actionsPopUp) that retains a reference to the UIPopoverController. This is used later to call dismissPopoverAnimated when I want to dismiss the popover. Here is an example of it's use:

-(void)shareWishToEmail:(id)sender
{
  [_actionsPopUp dismissPopoverAnimated:YES];
  [[WishCloudService sharedInstance] showMailer:self withItems:[NSArray arrayWithObject:self.item] delegate:self modal:YES];
}

In this method, I dismiss the popover first, and then perform the action associated with the button that was pressed in the popover. Unfortunately, this doesn't appear to work. The action gets performed, but the popover is not dismissed. In addition, it doesn't seem to get dismissed when the user clicks once outside of the popover. But if clicked outside again, it does get dismissed. Another observation is that the first click seems to hide/dismiss the drop shadow of the popover, but not the popover itself. It's the second click that dismisses the popover. However, no amount of calling dismissPopoverAnimated seems to dismiss the popover at all.

I've swapped in UIPopoverControllers that seem to work in other parts of the application, but get the same results, which leads me to believe that it is something specific to the UIView/UIViewController that I'm presenting the popover in. I am creating the view programmatically rather than through a NIB. It escapes me at the moment why I decided to do that, but I don't believe that it should be relevant. Someone please let me know otherwise. Here is my loadView method:

-(void)loadView
{
  self.view = [self createView:_item];
  self.currentView = self.view;
  _wishItemViews = [[NSMutableDictionary dictionary] retain];
  [_wishItemViews setObject:_currentView forKey:[NSNumber numberWithInteger:_currentIndex]];
}

I have a currentView property because I need to be able to slide new views in and out, and I'm using CATransition animations to do it. The currentView property is used to swap the views when it performs the transitions. Again, not sure if this is relevant, but I'm including it for completeness and just in case it does make a difference. Hopefully, that's enough information for someone to help point me in the right direction. Or at least prompt some additional questions that might help me think this through. Any help would be greatly appreciated.

2
  • Dismisses the drop shadow? Perhaps you have 2 popovers on top of each other?
    – jtbandes
    Aug 27, 2011 at 1:43
  • jtbandes, you were right on the money! It didn't really occur to me that there might be 2 popovers being overlayed. I assumed it was some kind of CALayer issue. When I set a breakpoint on the presentPopoverFromRect call, I found that it was being called twice. Why? Because I was setting the target/action twice on the toolbar item. The createView method in the controller was instantiating the view, whose init method was setting the target/action. Later in the createView method, I was again setting the target/action. Doh! Please submit your response, and I will mark it as the answer. Thanks!
    – djilo
    Aug 27, 2011 at 4:44

1 Answer 1

2

Another observation is that the first click seems to hide/dismiss the drop shadow of the popover, but not the popover itself.

It seems you have stumbled upon the rare double-popover. ;-)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.