-3

I would like to show a popover when the user clicks on a UIBarButtonItem. To make a popover work on an iPhone, I have searched and found WEPopover

Edited : Sorry, my question was confusing. I was trying to draw something similar to the iPad popover, but in an iPhone. I was asking if there is an alternative to it, such as adding a UIView over the other views or a new component from the iPhone SDK.

Thanks.

4

2 回答 2

3

看看FPPopover

代码真的很简单,有很多自动化的东西

//the view controller you want to present as popover
YourViewController *controller = [[YourViewController alloc] init]; 

//our popover
FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller]; 

//the popover will be presented from the okButton view 
[popover presentPopoverFromView:okButton]; 
于 2012-06-20T10:15:11.110 回答
1

将目标添加到您的 UIBarButtonItem

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithTitle:@"button!" style:UIBarButtonItemStyleBordered target:self action: @selector(showPopover:)];

并在您的目标中执行以下操作:

- (void)showPopover:(id)sender
{

    popoverController = [[[WEPopoverController alloc] initWithContentViewController:contentViewController] autorelease];
    [popoverController presentPopoverFromRect:sender.frame 
                                            inView:self.view 
                          permittedArrowDirections:UIPopoverArrowDirectionDown
                                          animated:YES];
}

此代码改编自 WEPopover https://github.com/werner77/WEPopover/blob/master/Classes/WEPopoverViewController.m提供的示例

于 2012-01-30T10:38:36.317 回答