iPhone:使用FPPopover类与UIBarButtonItem一起使用时出错 [英] iPhone: Error when using the FPPopover class when using it with a UIBarButtonItem

查看:80
本文介绍了iPhone:使用FPPopover类与UIBarButtonItem一起使用时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 FPPopover 类为iPhone创建弹出窗口。
我遵循自述文件中的确切步骤,但我没有使用xib文件中的UI按钮,而是使用以编程方式创建的UIBarButtonItem。但是,我收到以下错误:

I am using the FPPopover class which creates popups for iPhones. I followed the exact steps that are in the readme file but instead of using a UIbutton from a xib file, I am using a UIBarButtonItem created programmatically. But, I get the following error:


由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:' - [UIBarButtonItem superview]:无法识别选择器发送到实例0x6a3e420'

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIBarButtonItem superview]: unrecognized selector sent to instance 0x6a3e420'

我复制粘贴了与自述文件中相同的代码,但我刚刚更改了(UIButton *)okButton with(id)sender(id这里是UIBarButtonItem *)

I copy pasted the same code as in the readme file but I just changed the (UIButton*)okButton with (id)sender (id here is UIBarButtonItem*)

-(void)popover:(id)sender
{
    //the view controller you want to present as popover
    TestClass *controller = [[TestClass alloc] init];
    //our popover
    FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller];
    //the popover will be presented from the okButton view
    [popover presentPopoverFromView:sender];
    //release
    [controller release];
}

我想也许它与UIButButtonItem有关,而UIButButtonItem不是UIButton ?还是别的什么?我尝试将UIBarButtonItem转换为UIButton,但仍然给了我同样的错误。它的任何解决方案?

I was thinking maybe it has to do with the UIBarButtonItem which is not a UIButton? Or is it anything else? I tried converting the UIBarButtonItem into UIButton but still gave me the same error. Any solutions to it?

以下是另外一个注意事项:这是我以编程方式创建导航栏和条形按钮的方式:

One more note just in case: This is how I programmatically created the navigation bar along with the bar button:

UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(320, 0, 320, 44)];
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"By Clubs"];
[navBar pushNavigationItem:navItem animated:NO];
UIBarButtonItem *editButton = [[UIBarButtonItem alloc] initWithTitle:@"Filter"
                                               style:UIBarButtonItemStyleBordered
                                              target:self
                                              action:@selector(popover:)];


navItem.rightBarButtonItem = editButton;


推荐答案

presentPopoverFromView只接受UIView子类。 UIBarButtonItem不是UIView的子类,因此您需要找到与该按钮项相关的视图。这是我与FPPopoverController一起使用的解决方案

the presentPopoverFromView is only accepting a UIView subclass. UIBarButtonItem is not a subclass of UIView, so you need to find the view related to that button item. This is the solution I'm using with FPPopoverController

    UIBarButtonItem *buttonItem = sender;
    UIView* btnView = [buttonItem valueForKey:@"view"];
    //On these cases is better to specify the arrow direction
    [popover setArrowDirection:FPPopoverArrowDirectionUp];
    [popover presentPopoverFromView:btnView];

这应该有效!让我知道!

This should work! Let me know!

这篇关于iPhone:使用FPPopover类与UIBarButtonItem一起使用时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆