gpt4 book ai didi

iphone - 使用 XCode 5 的 iPhone 弹出窗口 View

转载 作者:可可西里 更新时间:2023-11-01 03:27:44 26 4
gpt4 key购买 nike

我想重复使用 this video 中描述的 iPhone 弹出窗口这正是我所需要的。

问题是我无法像视频中那样将 UIViewController 属性绑定(bind)到弹出窗口的 UIViewController

视频的一个不同之处在于它是使用 XCode 4.2 制作的,而我使用的是 XCode 5。

所以问题是:如何像 video 中那样为 iPhone 制作弹出窗口在 XCode 5 上?

Here is the XCode 5 project I am struggling with.

最佳答案

我找到了一种让弹出窗口以编程方式在 iPhone 和 iPad 上工作的方法!

  • 创建一个类别以使弹出窗口在 iPhone 上可用(更多详细信息 here)

    //UIPopover+Iphone.h
    @interface UIPopoverController (overrides)
    + (BOOL)_popoversDisabled;
    @end

    //UIPopover+Iphone.m
    @implementation UIPopoverController (overrides)
    + (BOOL)_popoversDisabled { return NO;
    }
    @end
  • 创建将显示弹出窗口的按钮并实现它调用的方法

ExampleUIViewController.h

@interface ExampleViewController : UIViewController <UIPopoverControllerDelegate>
@property (strong, nonatomic) UIButton *detailButton;
@property (nonatomic, retain) IBOutlet UIPopoverController *poc;

UIPopoverController poc 必须保存在一个实例变量中,更多细节 here .

ExampleUIViewController.m

- (void)viewDidLoad {
_detailButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_detailButton addTarget:self
action:@selector(showPop:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_detailButton];
}

-(void)showPop:(UIButton *)button {
UIViewController *detailsViewController = [[DetailsViewController alloc] initWithNibName:@"DetailsViewController" bundle:nil];
self.poc = [[UIPopoverController alloc] initWithContentViewController:detailsViewController];
[self.poc setDelegate:self];
[self.poc presentPopoverFromRect:_detailButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
  • 创建 UIViewController,它将包含弹出框内显示的内容(在示例中称为 DetailsViewController)

只需在您的项目中创建它,方法是右键单击 -> 新建文件 -> Objective c 类 -> UIViewController 并勾选“With XIB”框。

然后,当点击时,按钮旁边会出现一个弹出窗口。

在 iOs5 及更高版本上测试正常。

关于iphone - 使用 XCode 5 的 iPhone 弹出窗口 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19238526/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com