我创建了一个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
的viewcontoller中的按钮时,如何关闭popovercontroller
? 最佳答案
您正在分配Firstviewcontroller
的新实例,因此它不会消除前一实例的弹出窗口。
显示弹出框时,您需要传递旧实例,例如:
- (void)viewDidLoad
{
[super viewDidLoad];
controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:[NSBundle mainBundle]];
popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
[controller setFs:self]
}
并像这样解散:
-(IBAction)y:(id)sender
{
[fs.popoverController dismissPopoverAnimated:TRUE];
}
关于iphone - 如何关闭UIPopoverController?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14317252/