iosframeuibarbuttonitemuipopover

Get frame of an UIBarButtonItem


I have created an UIBarButtonItem inside a NavigationBar:

UIBarButtonItem *filtroFecha = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(filtrarFecha:)]autorelease];


    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects: addActivity, filtroFecha, nil];

Now I want to open a popover from this button, but I am not able to get the frame of the UIBarButtonItem.

if (_filtroActividadesView == nil) {
        self.filtroActividadesView = [[CRMFiltroActividadViewController alloc] init];
        _filtroActividadesView.delegate = self;
        self.filtroPopover = [[UIPopoverController alloc] 
                                  initWithContentViewController:_filtroActividadesView];               
    }

    [self.filtroPopover presentPopoverFromRect:CGRectMake(0, 0, 1400, 44) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

Thanks!!


Solution

  • Use presentPopoverFromBarButtonItem:permittedArrowDirections:animated:.

    [self.filtroPopover presentPopoverFromBarButtonItem:filtroFecha
                        permittedArrowDirections:UIPopoverArrowDirectionUp
                        animated:YES];