以下方法与导航栏按钮相关联。按下按钮时,会显示UIPopoverController
- (IBAction) showTablePopUp:(id) sender {
if (self.tablesPopoverController == nil) {
TablesPopOverViewController *tables = [[TablesPopOverViewController alloc]initWithNibName:@"TablesPopOverViewController" bundle:[NSBundle mainBundle]];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:tables];
popover.delegate = self;
popover.popoverContentSize=CGSizeMake(280.0, 327.0);
[tables release];
self.tablesPopoverController = popover;
[popover release];
}
[self.tablesPopoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
我想要做的是在第二次按下按钮时隐藏弹出窗口:
我该怎么做?
答案 0 :(得分:6)
这应该做你想要的:
- (IBAction) showTablePopUp:(id) sender {
if (self.tablesPopoverController == nil) {
TablesPopOverViewController *tables = [[TablesPopOverViewController alloc]initWithNibName:@"TablesPopOverViewController" bundle:[NSBundle mainBundle]];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:tables];
popover.delegate = self;
popover.popoverContentSize=CGSizeMake(280.0, 327.0);
[tables release];
self.tablesPopoverController = popover;
[self.tablesPopoverController presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self.tablesPopoverController dismissPopoverAnimated: YES];
self.tablesPopeverController = nil;
}
}