我尝试在UIScrollView中添加ViewControllers,并从xib加载VC。这是我的代码
let onevc = OneViewController()
self.addChildViewController(onevc )
self.scrollView.addSubview(onevc .view)
onevc.didMoveToParentViewController(self)
let twovc = TwoViewController()
var frame:CGRect = twovc.view.frame
frame.origin.x = 320
twovc.view.frame = frame
self.addChildViewController(twovc)
self.scrollView.addSubview(twovc.view)
twovc.didMoveToParentViewController(self)
self.scrollView.contentSize = CGSizeMake(640, self.view.frame.size.height)
self.scrollView.pagingEnabled = true
两个视图控制器都已添加,但它们不可见,scrollview只显示白色屏幕。我在ViewControllers中添加了一些元素,并且还测试我添加了 println("某些")因此,当加载视图时,它正在打印某些东西但是没有任何表现。我在这做错了什么?
答案 0 :(得分:0)
也许您忘了为视图控制器指定笔尖名称?
let onevc = self.storyboard!.instantiateViewControllerWithIdentifier("OneViewController")
or
let onevc = OneViewController(nibName: "OneViewController", bundle: nil)
第二个也一样。