Take the 2-minute tour ×

Could anyone please tell me what the rect and view should be? I do not understand what I shall pass to the selector. An example would be great!


share|improve this question

1 Answer 1

up vote 3 down vote accepted

I use this pretty often. Let's say you want to tap on an image and present a popover with information about it. Assuming you have a gesture recognizer with the selector method (handleImageTap:) on your image, here would be an example code to make that happen:

- (void)handleImageTap:(UIGestureRecognizer *)gesture {
    // initialize your popover view controller and assign it to your popoverController
    MyPopoverViewController *content = [[MyPopoverViewController alloc] init];
    popoverController = [[UIPopoverController alloc] initWithContentViewController:content];
    popoverController.popoverContentSize = CGSizeMake(600, 600);
    popoverController.delegate = self;
    [content release];

    if (popoverController.popoverVisible == NO) {
        // you can find the tappedImage through the gesture by searching up superviews if you don't already have a reference to it;
        [popoverController presentPopoverFromRect:[tappedImage frame] inView:self.view 
        permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];                  
    else {
        [popoverController dismissPopoverAnimated:YES];

So basically, view will be self.view becuase you are displaying it from the current view controller. The rect is just whatever rect you want the popover to display from. In this case, it is set up to be displayed from the frame of an image. I hope this helps you. If something is still confusing, I'll be happy to try and clear it up

share|improve this answer
Thank you, no need for further explanation, this is more than enough! I understand what they are now. –  LuckyLuke May 28 '11 at 17:43
You're more than welcome. I'm glad to help out –  justin May 28 '11 at 17:45

Your Answer


