xcode 关闭弹出视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13603708/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dismiss the popover view
提问by iOS developer
I have a root view controller in which I load a sub view that contains three buttons. When I touch one of them a popover is shown. The popover contains an image view and a bar with a Done button. I want to dismiss this popover when the Done button is touched. To accomplish this I am using this code
我有一个根视图控制器,我在其中加载了一个包含三个按钮的子视图。当我触摸其中一个时,会显示一个弹出窗口。弹出框包含一个图像视图和一个带有完成按钮的栏。我想在触摸完成按钮时关闭这个弹出窗口。为了实现这一点,我正在使用此代码
- (IBAction)btnDone:(UIBarButtonItem *)sender {
[self.view removeFromSuperview];
[APPDELEGATE.parkDetail. popoverController dismissPopoverAnimated:YES];
// [APPDELEGATE.parkDetail.popoverController dismissPopoverAnimated:YES ];
}
and the popover is presented like this
弹出框是这样呈现的
- (IBAction)btnParkMap:(id)sender {
[popoverController dismissPopoverAnimated:YES];
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
} else {
parkMap * v = [[parkMap alloc]initWithNibName:@"parkMap" bundle:nil];
v.contentSizeForViewInPopover = CGSizeMake(350, 300);
popoverController = [[UIPopoverController alloc] initWithContentViewController:v];
CGRect popRect = CGRectMake(self.btnShowPopover.frame.origin.x+330,
self.btnShowPopover.frame.origin.y+170,
self.btnShowPopover.frame.size.width,
self.btnShowPopover.frame.size.height);
[popoverController presentPopoverFromRect:popRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}
回答by Shyantanu
Try this code
试试这个代码
[self dismissViewControllerAnimated:YES completion:nil];
Or try @nirav's ans
或者试试@nirav 的回答
回答by NiravPatel
Try to write below code
尝试编写下面的代码
[yourPopOverobject dismissPopoverAnimated:YES];
Let me know whether it is working or not..
让我知道它是否有效..
Happy Coding!!!!!
快乐编码!!!!!
回答by SameSung Vs Iphone
The PopUpOver can beswitch off the default contextual menu of UIWebView. This is easy because we only need to set the CSS property “-webkit-touch-callout” to “none” for the body element of the web page. We can do this using JavaScript in the UIWebView delegate method “webViewDidFinishLoad:”…
PopUpOver 可以关闭 UIWebView 的默认上下文菜单。这很容易,因为我们只需要将网页的 body 元素的 CSS 属性“-webkit-touch-callout”设置为“none”。我们可以在 UIWebView 委托方法“webViewDidFinishLoad:”中使用 JavaScript...
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:@"document.body.style.webkitTouchCallout='none';"];
}
回答by Rose
- (IBAction)btnDone:(UIBarButtonItem *)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
回答by NiravPatel
Try to check below code...
尝试检查以下代码...
if ([popoverobject isPopoverVisible]) {
[popoverobject dismissPopoverAnimated:YES];
[popoverobject release];
}
}
}
#pragma mark -
#pragma mark UIPopoverController delegate
-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
//if (popoverController == popoverobject) {
[popoverobject release];
// }
}
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController {
NSLog(@\"popover about to be dismissed\");
return YES;
}
let me know is it working or not...
让我知道它是否有效...