显示来自CGRect按钮的popover

时间:2011-11-10 15:51:49

标签: iphone

我以编程方式创建了一个按钮,以添加到rightBarButtonItem中。我必须使用UINavigationController在右上角创建一些按钮,所以我将它们放在一个containerView中,然后将它作为正确的barButtonItem customView放在init方法中。如果我的button和containerView声明如下:

UIButton *filterButton = [[UIButton alloc] initWithFrame:CGRectMake(49, 0, 44, 44)];
[filterButton setTitle:@"Filter" forState:UIControlStateNormal];
[filterButton addTarget:self action:@selector(FilterButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 248, 44)];

如何从filterButton rect获取popover?到目前为止,我的方法看起来像这样,但它不正确。

- (IBAction)FilterButtonPressed:(id)sender {
// other code
    [self.FilterPopover presentPopoverFromRect:button.superview.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

1 个答案:

答案 0 :(得分:3)

我通常会像这样显示popover:

 [self.FilterPopover presentPopoverFromRect:button.bounds inView:button permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];