- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是firstPopoverViewController.h代码:
#import <UIKit/UIKit.h>
@interface firstPopoverViewController : UIViewController
@end
这是我的 firstPopoverViewController.m 代码:
#import "firstPopoverViewController.h"
@interface firstPopoverViewController ()
@end
@implementation firstPopoverViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.contentSizeForViewInPopover = CGSizeMake(300, 290);
// Header label
UILabel *h1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 85)];
h1.font = [UIFont fontWithName:@"myFont" size:22.0];
h1.textColor = [UIColor blackColor];
h1.textAlignment = NSTextAlignmentCenter;
h1.text = @"Heading";
h1.numberOfLines = 0;
h1.backgroundColor = [UIColor greenColor];
// Ok button BG View
UIView *buttonBG = [[UIView alloc] initWithFrame:CGRectMake(0, 300-75, 300, 75)];
buttonBG.backgroundColor = [UIColor greenColor];
// Ok button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(300/2-130/2, 290-35-15, 130, 35);
button.backgroundColor = [UIColor whiteColor];
[button setTitle:@"OK" forState:UIControlStateNormal];
[button addTarget:self action:@selector(closePop) forControlEvents:UIControlEventTouchUpInside];
button.adjustsImageWhenHighlighted=YES;
// Adding views
[self.view addSubview:h1];
[self.view addSubview:buttonBG];
[self.view addSubview:button];
}
-(void)closePop {
}
@end
然后是ViewController.h:
#import <UIKit/UIKit.h>
#import "firstPopoverViewController.h"
@interface ViewController : UIViewController
@property (strong, nonatomic) UIButton *popButton;
@property (strong, nonatomic) firstPopoverViewController *firstPopoverViewController;
@property (strong, nonatomic) UIPopoverController *firstPopover;
@end
最后是 ViewController.m:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
/* ##### UIPopController stuff ##### */
UIImage *popButtonImage = [UIImage imageNamed:@"menu.png"];
_popButton = [UIButton buttonWithType:UIButtonTypeCustom];
_popButton.frame = CGRectMake(0, 0, 73, 66);
[_popButton addTarget:self action:@selector(openPop) forControlEvents:UIControlEventTouchUpInside];
_popButton.adjustsImageWhenHighlighted=NO;
[_popButton setImage:popButtonImage forState:UIControlStateNormal];
[self.view addSubview:_popButton];
}
-(void)openPop {
if (_firstPopoverViewController == nil) {
//Create the _firstPopoverViewController.
_firstPopoverViewController = [[firstPopoverViewController alloc] init];
}
if (_firstPopover == nil) {
_firstPopover = [[UIPopoverController alloc] initWithContentViewController:_firstPopoverViewController];
_firstPopover.popoverContentSize = CGSizeMake(300, 290);
[_firstPopover presentPopoverFromRect:CGRectMake(0,0, 73, 66) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
NSLog(@"show");
} else {
NSLog(@"dismiss");
[_firstPopover dismissPopoverAnimated:YES];
_firstPopover = nil;
}
}
@end
这是显示按钮的非常基本的代码,当我单击此按钮时它会显示弹出窗口。我想使用 firstPopoverViewControll.m 文件中的按钮关闭此弹出窗口。有一个 closePop{} 方法,我应该在里面放什么来关闭这个弹出窗口?谢谢。
顺便说一句,如您所见,我是初学者,我研究了 stackoverflow 并且有一些与委托(delegate)有关的解决方案,这似乎对其他人有用,但对我没有用,你能告诉我一个解决方案吗我发布的代码?非常感谢你们。
最佳答案
可能有一个我不知道的更简单的方法,但下面的方法应该有效:
使用 NSNotificationCenter 将通知发回包含 UIPopOverController 的 ViewController,告诉它关闭弹出窗口。
首先,在ViewController.m viewDidLoad中添加:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closePop:) name:@"ClosePopOver" object:nil];
然后在ViewController.m中添加如下方法:
- (void)closePop:(NSNotification *)notification {
[_firstPopover dismissPopoverAnimated:YES];
}
然后在 irstPopoverViewController.m 中:
- (void)closePop {
[[NSNotificationCenter defaultCenter] postNotificationName:@"ClosePopOver" object:nil];
}
这应该可以解决问题。
关于ios - 从其 UIViewController 中的按钮关闭 UIPopoverController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20126770/
如上所述,在 iOS8 中,[UIPopoverController presentPopoverFromRect] 不再适用于 [UIApplication sharedApplication].k
我有一个 UISearchBar。当用户触摸 UISearchBar 时,会显示一个包含结果的 UITableView 的 UIPopoverController。当用户输入时,结果就会出现。 我希望
我正在尝试创建一个如上所示的弹出窗口。 它可以是一个按钮或只有一个项目的 TableViewController。 我查看了很多教程,但它们似乎都比必要的复杂得多。 有没有办法在不创建新的 ViewC
有谁知道是否可以在 iPad 上为 UIPopOverController 设置透明背景? 我想在弹出框内放置一个半透明 View (因此希望弹出框本身具有透明背景)。 我认为这是不可能的……但我很想
如何“执行选择器”到uipopovercontroller的parentviewcontroller? 我有从uiviewcontroller中解放出来的uipopovercontroller,这个u
希望有办法做到这一点。希望只显示 View 周围的边框,顶部没有 40px 标题栏。可能吗? 最佳答案 已回答...我正在使用导航 Controller 初始化它。一旦我删除了它,我就没有得到标题栏。
我有一个通用应用程序。在 iPad 上,当按下注释图钉时,它会显示标注气泡。当我按下关闭按钮时,它会加载一个带有详细 View 的 uipopovercontroller。我想知道的是如何加载 uip
我想知道如何制作一个没有箭头的 UIPopoverController事实上我想模拟这样的事情: 看看 没有箭头 有一个标题以某种方式位于 UIPopoverController 的扩展顶部边框内部,
我有一个显示表格的 UIPopoverController。我使用 PresentFromBarButtonItem 方法。 我怎样才能给弹出窗口显示一个标题,UISpliter 做了多少列表? 最佳
我有一个问题,this question 的回答最多。 . 但是,我的任务略有不同。我想将 UIImageViews 从 UIPopover Controller 拖放到另一个 UIView,但弹出框
我正在以这种方式创建一个弹出框: popoverController = [[UIPopoverController alloc]initWithContentViewController:brows
我有一个 UIPopoverController由 TableView 组成。这个弹出式 Controller 显示得很好,我已经设置了委托(delegate) didSelectRowAtIndex
是否可以从第一个弹出窗口 UIButton 单击打开另一个 uipopovercontroller?如果是,那我该怎么做? 现在我正在使用给定的代码从 UIBarButtonItem 打开一个弹出窗口
我正在窗口内切换 View 。方向有时会混淆。 在其中一个窗口中,当我尝试显示应附加到工具栏按钮的弹出窗口时,它显示在屏幕上的位置。如果我物理地改变设备的方向,弹出窗口会在正确的位置重绘。如果我再次切
iOS 9 中 PopoverController 的正确代码是什么?在任何地方都可以找到此代码的正确代码? @IBAction func share(发送者:UIBarButtonItem){
我有一个普通的 UIPopoverController,它是这样制作的: -(IBAction)btKBIs_click:(id)sender { if(kbiPopOver != NULL)
我有一个按钮,当按下它时会显示一个 View Controller ,这是一个通用应用程序。 在 iPhone 上, View Controller 被推送到导航堆栈上。在 iPad 上,它显示在弹出
在 iOS 7 中,UIPopoverControllers 具有视差效果(前景悬停在背景之上)。 这在处于纵向模式的 UISplitViewController 中尤其难看。 线条不在同一水平面上。
我知道 UIPopOverController 可以提供标准下拉菜单,但我很好奇它是否可以提供动态下拉菜单。 动态下拉菜单将更进一步,单击列表中的任何项目都可以展开更多选项或执行某些其他操作,类似于文
我发现在呈现 UIPopoverController 时,并非呈现 View 中的所有控件都被禁用。具体来说,导航栏按钮(例如“后退”)仍然可选。我认为这是一个缺陷 - 它允许弹出窗口保留在屏幕上,而
我是一名优秀的程序员,十分优秀!