场景是这样的
创建新项目选项卡式应用程序。添加新的 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)。
当我从 Tab 运行时
我认为设置已经正确(因为它在 UIViewController 中运行良好)
已将文件所有者设置为 TestViewController
已经绑定(bind)了outlet
谢谢!
最佳答案
我认为您正在使用推断尺寸的 ViewController,在属性检查器中将其更改为 iPhone 4 英寸(模拟指标 -> 尺寸并根据该尺寸设置按钮框架。
希望这有帮助:)
关于ios - 单击选项卡时,选项卡栏 Controller 不显示 XIB UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30011396/