在Interface Builder中为Iphone创建popover视图控制器

Dou*_*ith 3 iphone objective-c uipopovercontroller ios uistoryboard

我该怎么做呢?我知道我必须给popover一个视图控制器,它构建它的视图,但我不知道如何在Interface Builder中构建这个视图(比如添加标签和按钮等等).

我是否只是在普通的故事板中进行操作,并且有一个随机地与其他任何东西无关的故事板,坐在角落里?

我是否创建了另一个故事板?

即使我的项目都是故事板,我也会创建一个xib吗?

我是以编程方式创建的吗?

u.g*_*gen 8

由于你没有在你的问题中指定目标设备,我给你Ipad答案

IPAD:

转到您的故事板拖放一个viewcontroller或多个tableviewcontroller你.然后viewcontroller在故事板上创建一个想要的segue 到新拖放viewcontroller.选择你的segue为popOver.

在此输入图像描述

在此输入图像描述

确保在segue设置中选择锚点,如上图所示.然后,您需要编辑弹出窗口的大小.如果它uiviewcontroller选择了它的视图,如果它tableviewcontroller在界面构建器的左侧选择其tableview并编辑它的大小.

第一:

在此输入图像描述

第二:

在此输入图像描述

之后,自定义您的弹出视图控制器(拖放视图控制器)添加按钮,标记您想要的任何内容.

如果你打算在你的popover中做更多的事情:别忘了创建新文件 - > uiviewcontroller或uitableviewcontroller的子类.然后将它与故事板上新创建的viewcontroller关联.

在此输入图像描述

苹果手机:

iphone中没有Popover控制器

但你尝试使用第三方https://github.com/50pixels/FPPopover解决方案,模仿iphone中的弹出行为QuartzCore

我会尝试以下:

第一:

再次拖放uiviewcontoller到您的故事板,然后创建一个新的文件 - >子类uiviewcontroller.

这个新内容uiviewcontroller将位于故事板的角落

然后将故事板中的uiviewcontroller与新创建的文件相关联,假设您创建了一个新的文件名YourViewController.为您的视图提供一个storyboard id并选择其类名.

在此输入图像描述

-(IBAction)buttonClicked:(UIButton*)okButton
{
    //the view controller you want to present as popover
    YourViewController *controller = [[YourViewController alloc] init]; 

    //if [[YourViewController alloc] init]; doesn't work try this
   // UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                     bundle:nil];
    //YourViewController *controller = [sb instantiateViewControllerWithIdentifier:@"YourViewController"]; 

    //our popover
    FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller]; 

    //the popover will be presented from the okButton view 
    [popover presentPopoverFromView:okButton]; 

    //no release (ARC enable)
    //[controller release];
}
Run Code Online (Sandbox Code Playgroud)

注意:我之前没有使用过FPPopover所以不知道如何安排屏幕尺寸,但是在他们的文档中必须进一步解释才能阅读它.