Search code examples
iosuitabbarcontrollerpopover

present view controller on selecting tabbar item


how to present view controller when tabbar item clicked. I just want to display as a popover . Using storyboard

i found that solution but this is not working

  AddImage *yourViewController= (AddImage*)  [self.tabBarController.viewControllers objectAtIndex:3];

    CGFloat tabBarHeight = self.tabBarController.tabBar.bounds.size.height;
    CGRect rect = CGRectMake(0, 0, tabBarHeight, tabBarHeight);
    [AddImage presentPopoverFromRect:rect
                                                                             inView:self.tabBarController.tabBar
                                                           permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

Solution

  • For this purpose
    1) set the delegate of the tabbar

    2) implement the method : -(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item

    3) now display popover for the specific item