0

我在我的应用程序中使用 WEPopover 来弹出一个包含一些按钮的弹出框控制器,当我将 wepopover 控制器操作放入 tabbarIteam 时它可以工作,但是当我单击 UIButton 时我需要获得弹出框。如何做到这一点这是我用于显示弹出框的 barbuttonitem 代码.

-(IBAction)_clickbtnAccount:(id)sender
{
    if (!self.popoverController)
    {
        UIViewController *contentViewController = [[pageAccount alloc]initWithNibName:@"pageAccount" bundle:nil];
        self.popoverController = [[[popoverClass alloc] initWithContentViewController:contentViewController] autorelease];
        self.popoverController.delegate = self;
        self.popoverController.passthroughViews = [NSArray arrayWithObject:self.navigationController.navigationBar];

        [self.popoverController presentPopoverFromBarButtonItem:sender
                                       permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown) 
                                                       animated:YES];
        [contentViewController release];
    }
    else
    {
        [self.popoverController dismissPopoverAnimated:YES];
        self.popoverController = nil;
    }
}

-(IBAction)_clickbtnAccount:(id)sender
{
    if (!self.popoverController)
    {
        UIButton *senderButton = (UIButton *)sender;
        [self.popoverController presentPopoverFromRect:[senderButton frame]
                                                inView:@"pageAccount"
                              permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown) 
                                              animated:YES];        
    }
    else
    {
        [self.popoverController dismissPopoverAnimated:YES];
        self.popoverController = nil;
    }
}
4

3 回答 3

3

所以你不想显示 a WEPopoverfrom anUIBarButtonItem但 from an UIButton,对吧?!只需使用

- (void)presentPopoverFromRect:(CGRect)rect 
                    inView:(UIView *)view 
  permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections 
                  animated:(BOOL)animated;

代替

- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item 
           permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections 
                           animated:(BOOL)animated;

并传入你的UIButton.

以您的代码为例:

-(IBAction)_clickbtnAccount:(id)sender
{
    if (!self.popoverController) {

        UIViewController *contentViewController = [[pageAccount alloc]initWithNibName:@"pageAccount" bundle:nil];
        self.popoverController = [[[popoverClass alloc] initWithContentViewController:contentViewController] autorelease];
        self.popoverController.delegate = self;
        self.popoverController.passthroughViews = [NSArray arrayWithObject:self.navigationController.navigationBar];

        UIButton *senderButton = (UIButton *)sender;
        [self.popoverController presentPopoverFromRect:[senderButton frame]
                        inView:self.view
                                        permittedArrowDirections:(UIPopoverArrowDirectionUp|UIPopoverArrowDirectionDown) 
                  animated:YES];

        [contentViewController release];
    } else {
        [self.popoverController dismissPopoverAnimated:YES];
        self.popoverController = nil;
    }
}
于 2011-10-04T13:54:53.400 回答
0

使用公认的解决方案,我在 iOS 7 下遇到了 WEPopover 的旋转问题:基本上它指向导航栏左侧 UIBarButtonItem 中的自定义按钮,但旋转时弹出窗口移动到屏幕右侧并停留在那里在进一步的旋转。

于 2013-11-01T15:18:34.093 回答
0

WEPopover 基本上用于在弹出框内显示多个选项,并使用 UITableview 进行很多控制。

这就是我使用 WEPopOver 在按钮单击时显示弹出窗口的方式

-(void)showPopOver:(id)sender{
    if (self.popoverController) {
            [self.popoverController dismissPopoverAnimated:YES];
            self.popoverController = nil;
        } 
        PopOverTable *contentViewController = [[PopOverTable alloc] initWithStyle:UITableViewStylePlain];
        contentViewController.delegatePopoverItemSelectedDelegate=self;
            rectForPopover = [self.view convertRect:btn.bounds fromView:btn];
                self.popoverController = [[[popoverClass alloc] initWithContentViewController:contentViewController] autorelease];

                if ([self.popoverController respondsToSelector:@selector(setContainerViewProperties:)]) {
                    [self.popoverController setContainerViewProperties:[self improvedContainerViewProperties]];
                }
                self.popoverController.delegate = self;
                [self.popoverController presentPopoverFromRect:rectForPopover  
                                                        inView: self.view 
                                      permittedArrowDirections:(UIPopoverArrowDirectionAny)
                                                      animated:YES];
        }
于 2011-10-04T14:10:06.293 回答