我正在使用为 iPhone 创建弹出窗口的FPPopover类。我遵循了自述文件中的确切步骤,但我没有使用 xib 文件中的 UIbutton,而是使用以编程方式创建的 UIBarButtonItem。但是,我收到以下错误:
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIBarButtonItem superview]:无法识别的选择器发送到实例 0x6a3e420”
我复制粘贴了与自述文件中相同的代码,但我只是将 (UIButton*)okButton 更改为 (id)sender (id 这里是 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];
}
我在想也许它与不是 UIButton 的 UIBarButtonItem 有关?或者是别的什么?我尝试将 UIBarButtonItem 转换为 UIButton 但仍然给了我同样的错误。有什么解决办法吗?
以防万一:这是我以编程方式创建导航栏和栏按钮的方式:
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;