我想重用
this video中描述的iPhone的popover,这正是我需要的.
问题是我无法像视频中那样将UIViewController属性绑定到popover的UIViewController.
问题是我无法像视频中那样将UIViewController属性绑定到popover的UIViewController.
与视频的一个不同之处在于它是使用XCode 4.2制作的,而我使用的是XCode 5.
所以问题是:如何在XCode 5的video上制作iPhone的弹出窗口?
解决方法
我找到了一种让popover以编程方式在iPhone和iPad上工作的方法!
>创建一个类别以在iPhone上提供popover(更多细节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 class – > UIViewController并勾选“With XIB”框.
然后点击按钮旁边会出现一个弹出窗口.
在iOs5及以上版本上测试OK.