使用XCode 5的iPhone的Popover视图 [英] Popover view for iPhone using XCode 5

查看:133
本文介绍了使用XCode 5的iPhone的Popover视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重复使用此视频中描述的iPhone的popover,这正是我所需要的。

问题是我无法将 UIViewController 属性绑定到popover的 UIViewController 之类的在视频中。

I wanted to reuse the popover for iPhone described in this video which is exactly what I need.

The problem is that I couldn't bind a UIViewController property to the popover's UIViewController like in the video.

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

One difference with the video is that it has been made using XCode 4.2 and I'm using XCode 5.

所以问题是:如何在iPhone上制作popover,就像在XCode 5上的视频一样?

So the question is: How to make a popover for iPhone like in the video on XCode 5?

这是XCode 5项目我正在努力。

推荐答案

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

I figured out a way to get popover to work on iPhone and iPad programmatically !


  • 创建一个类别以在iPhone上提供popover(更多详情这里

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

//UIPopover+Iphone.m
@implementation UIPopoverController (overrides)
+ (BOOL)_popoversDisabled { return NO;
}
@end


  • 创建将显示的按钮popover并实现它调用的方法

  • Create the button which will show the popover and implement the method it calls

    ExampleUIViewController.h

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

    UIPopoverController poc必须保存在一个实例变量中,更多细节在其他地方

    UIPopoverController poc has to be held in an instance variable, more details 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 popover(在示例中称为DetailsViewController)

    • 只需在项目中右键单击创建它 - >新文件 - >目标c class - > UIViewController并勾选With XIB框。

      Simply create it in your project by a right click -> New File -> Objective c class -> UIViewController and tick the box "With XIB".

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

      Then a popover will appear right next to the button when tapped.

      在iOs5及以上版本上测试好。

      Tested OK on iOs5 and above.

      这篇关于使用XCode 5的iPhone的Popover视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆