我创建了一个UIPopoverController
并在单击时将其添加到视图控制器UIButton
中,如下所示
- (void)viewDidLoad
{
[super viewDidLoad];
controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
}
- (IBAction)showPopover:(UIButton *)sender
{
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
} else {
CGRect popRect = CGRectMake(self.btnShowPopover.frame.origin.x,
self.btnShowPopover.frame.origin.y,
self.btnShowPopover.frame.size.width,
self.btnShowPopover.frame.size.height);
[popoverController presentPopoverFromRect:popRect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
}
btnShowPopover
是UIButton
中viewcontroller
,popoverController
是UIPopoverController
。
popovercontroller
单击按钮时看起来很好。
但是当我UIButton
单击secondviewcontroller
我为此使用了以下代码
-(IBAction)y:(id)sender{
fs = [[Firstviewcontroller alloc] initWithNibName:@"FIrstscreen" bundle:[NSBundle mainBundle]];
[fs.popoverController dismissPopoverAnimated:TRUE];
}
但它没有用。
popovercontroller
单击添加到的视图控制器中的按钮时如何关闭popovercontroller
?