单击UIBarButtonItem时iPhone中的弹出窗口

时间:2012-01-30 10:31:17

标签: iphone uibarbuttonitem popover

我想在用户点击UIBarButtonItem时显示一个弹出框。为了在iPhone上制作popover,我搜索并找到了WEPopover

已编辑:抱歉,我的问题很混乱。我试图绘制类似于iPad popover的东西,但是在iPhone中。我问是否有替代方案,例如在其他视图上添加UIView或从iPhone SDK添加新组件。

感谢。

2 个答案:

答案 0 :(得分: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]; 

答案 1 :(得分: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

提供的示例