ios - 单击选项卡时,选项卡栏 Controller 不显示 XIB UIViewController

标签 ios objective-c uiviewcontroller

场景是这样的

创建新项目选项卡式应用程序。添加新的 Controller ,带有 XIB 文件的 TestViewController,在 XIB 文件中只需添加一个带有文本“TestViewControllerButton”的按钮。

如果我在 FirstViewController 中创建一个按钮,并添加一个操作以转到 TestViewController,则会显示 XIB 文件中的按钮。

TestViewController* vc = [[TestViewController alloc] init];
[self presentViewController:vc animated:YES completion:nil];

问题是当我将 TestViewController 添加到选项卡 Controller (索引 2,从 0 开始)时,它不显示 XIB(我的意思是,按钮不显示)。

这是我的步骤。我在选项卡 Controller 中添加 UIViewController,然后在 Identity Inspector 中将类更改为 TestViewController。然后将选项卡栏项添加到 TestViewController 并将其链接到选项卡栏 Controller ,这样当单击最后一个选项卡时,它就会链接到 TestViewController。但问题是,XIB中的按钮没有显示(我在TestViewController.xib中添加按钮)。

是的,当然我可以直接在我的 TestViewController 的 Main.storyboard 中添加按钮,但我的想法是我想在 TestViewController XIB 中管理 UI,而 main.storyboard 只是加载 TestViewController 图像中的 View 。

好的,我添加一些屏幕截图以帮助理解。当我以编程方式在 UIViewController 中运行时,此屏幕运行良好(上面的代码 - self presentViewController:vc animated:YES completion:nil)。

Run in UiViewController

当我从 Tab 运行时

enter image description here

我认为设置已经正确(因为它在 UIViewController 中运行良好)

Main storyboard custom class controller

已将文件所有者设置为 TestViewController

File Owner

已经绑定(bind)了outlet

Outlet

谢谢!

最佳答案

我认为您正在使用推断尺寸的 ViewController,在属性检查器中将其更改为 iPhone 4 英寸(模拟指标 -> 尺寸并根据该尺寸设置按钮框架。

enter image description here enter image description here

希望这有帮助:)

关于ios - 单击选项卡时,选项卡栏 Controller 不显示 XIB UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30011396/

相关文章:

ios - 正确链接 HUDLayer 到 GameplayLayer

objective-c - 将 C 转换为 Obj-C 文件读取代码

objective-c - 什么比例,从像素到米将是最好的和更可取的?

ios - 找不到属性 'navigationController'。 UIView界面

swift - 如何删除 UIViewController 过渡动画?

ios - 如何为屏幕上的 UIViewController "off"的一些 subview 和屏幕上的其他 View "on"设置动画?

iphone - 我的 UIViewController 怎么知道是谁把它放到堆栈上的?

ios - 推送通知可以跳过通知中心吗?

IOS:仅使用多点触控缩放 uiscrollview

ios - 在 Iphone 中,在哪里存储大量但临时的数据,如 1000 张图像