Tuesday, 18 February 2014

How to popovercontroller in iphone?

  • Create a category to make popover available on iPhone.
//UIPopover+Iphone.h
@interface UIPopoverController (overrides)
+ (BOOL)_popoversDisabled;
@end
//UIPopover+Iphone.
@implementation UIPopoverController (overrides)
+ (BOOL)_popoversDisabled { return NO;
}

  • Create the button which will show the popover and implement the method it calls
- (void)viewDidLoad {
   yourButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [yourButton addTarget:self
                action:@selector(showPop:)
      forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview: yourButton];
}

-(void)showPop:(UIButton *)button {
   UIViewController *detailsViewController = [[DetailsViewController alloc] initWithNibName:@"DetailsViewController" bundle:nil];
   poc = [[UIPopoverController alloc] initWithContentViewController:detailsViewController];
   [poc setDelegate:self];
   [poc presentPopoverFromRect:_detailButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}

also you can popover from UIBarButton.

[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

No comments:

Post a Comment