gpt4 book ai didi

iphone - 在 Interface Builder 中为 Iphone 创建弹出 View Controller

转载 作者:可可西里 更新时间:2023-11-01 06:22:06 25 4
gpt4 key购买 nike

我该怎么做呢?我知道我必须给 popover 一个 View Controller ,它从中构造它的 View ,但我不知道如何在 Interface Builder 中构造这个 View (比如添加标签和按钮等等)。

我是否只是在普通的 Storyboard 中做这件事,并且有一个 Storyboard 随机地没有连接到任何其他东西,坐在角落里?

我是否创建另一个 Storyboard?

即使我的项目全是 Storyboard,我也要创建 xib 吗?

我是否以编程方式创建它?

最佳答案

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

IPAD:

转到 Storyboard,拖放 viewcontrollertableviewcontroller 由您决定。然后在 Storyboard上创建一个从所需的 viewcontroller 到新拖放的 viewcontroller 的 segue。选择您的 segue 作为 popOver

enter image description here

enter image description here

确保您在 segue 设置中选择了一个 anchor ,如上图所示。然后你需要编辑你的 popover 的大小。如果它是一个 uiviewcontroller 选择它的 View ,如果它是一个 tableviewcontroller 选择它在界面构建器左侧的 tableview 并编辑它的大小。

首先:

enter image description here

第二个:

enter image description here

在那之后自定义你的弹出 View Controller (拖/放 View Controller )添加按钮,标记任何你想要的。

如果您要在弹出窗口中执行其他操作:不要忘记创建新文件 -> uiviewcontroller 或 uitableviewcontroller 的子类。然后将它与 Storyboard上新创建的 View Controller 相关联。

enter image description here

IPHONE:

iphone 中没有 Popover Controller

但是你尝试使用第三方https://github.com/50pixels/FPPopover使用 QuartzCore

模仿 iphone 中弹出行为的解决方案

我会尝试以下操作:

首先:

再次拖放一个 uiviewcontoller 到你的 Storyboard,然后创建一个新的 file-> uiviewcontroller 的子类。

这个新的 uiviewcontroller 将位于 Storyboard的角落

然后将 Storyboard中的 uiviewcontroller 与新创建的文件相关联,假设您使用 YourViewController 创建了一个新文件名。为您的 View 提供 Storyboard ID 并选择其类名。

enter image description here

-(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];
}

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

关于iphone - 在 Interface Builder 中为 Iphone 创建弹出 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15685106/

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