我的 UIView 没有渲染 [英] My UIView isn't rendering
问题描述
我是 iOS 开发的新手,我正在努力理解这些部分是如何组合在一起的,以及如何最好地使用 Interface Builder(是的,我想使用 IB 并且了解如何它与代码的变化有关).
I'm new to iOS development, and I'm struggling to understand how the pieces fit together, and how to best use the Interface Builder (yes, I want to use IB and understand how it relates to changes in code).
这是我目前的情况:
我创建了一个
PageViewController : UIPageViewController
类,它与我在 IB 中的页面视图控制器场景"相关联.这是初始视图控制器.
I created a class
PageViewController : UIPageViewController
, which I have associated with my "Page View Controller Scene" in IB. This is the initial view controller.
我创建了一个 Page1ViewController : UIViewController
类,它与 IB 中的Page1 View Controller Scene"相关联.同样在 IB 中,我在该场景中添加了一个 UIView
,它有一个不透明的白色背景和一个标签.
I created a class Page1ViewController : UIViewController
, which I have associated with "Page1 View Controller Scene" in IB. Also in IB, I have added a UIView
to that scene, that has an opaque white background and a single label in it.
在 PageViewController
的 viewDidLoad
方法中,我执行以下操作:
In PageViewController
's viewDidLoad
method, I do the following:
setViewControllers([Page1ViewController()],方向:UIPageViewControllerNavigationDirection.Forward,动画:真,完成:无)
在 PageViewController
和 Page1ViewController
的 viewDidLoad
方法中,我有一个 println
并且都显示,所以我知道它们正在加载......但是当我运行我的应用程序时,我有一个空白的黑屏.
In both the viewDidLoad
method of both PageViewController
and Page1ViewController
, I have a println
and both are displaying, so I know they are getting loaded...but when I run my app, I have a blank black screen.
这是我想要完成的:
PageViewController
有多个我想在 IB 中设计的自定义页面(它们不像开箱即用的日历示例,其中数据源确定每个页面视图)
PageViewController
has multiple custom pages that I want to design in IB (they are not like the out-of-the-box calendar example, where a data source determines each page view)
当应用程序启动时,我希望 PageViewController
显示第一页 (PageView1Controller
)
When the app starts, I want PageViewController
to display the first page (PageView1Controller
)
我对 Swift 很满意,但目前 UIKit 框架有点令人生畏.任何指导将不胜感激.
I'm comfortable with Swift, but the UIKit framework is a little daunting at the moment. Any guidance would be appreciated.
推荐答案
我知道你说过你将 PageViewController 设置为你的初始视图控制器,但你确定你这样做是正确的.它应该类似于下面的屏幕截图.
I know you've said you set the PageViewController as your initial view controller but are you sure you did this correctly. It should look similar to the screenshot below.
我刚刚用页面控制器完成了一个简单的项目,然后它在视图中确实加载了以下内容:-
Ive just done a simple project with a page controller and then its in view did load did the following:-
let pagevc1 = UIViewController()
pagevc1.view.backgroundColor = UIColor.redColor()
self.setViewControllers([pagevc1], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)
这似乎显示正常.你是如何初始化 Page1ViewController 视图控制器的?
Which seems to display fine. How are you initialising the Page1ViewController view controller?
这篇关于我的 UIView 没有渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!