我在我的应用程序中使用RTPagingViewController,我使用了objective c,并通过桥将其链接到我的swift项目。 它的工作原理与其演示相同。 有一个问题,当我滚动我的 View 时,编译了 View Controller 的代码,例如, View 确实触发了加载,但是我的 Storyboard和连接到 ViewControllers 的 UIViewContollers 没有显示我设计的内容。 所以我不能用 Storyboard设计我的应用程序,我应该以编程方式完成它。 我该如何解决这个问题?
class ViewController: RTPagingViewController {
let c1 = firstViewController()
let c2 = secondViewController()
let c3 = thirdViewController()
override func viewDidLoad() {
super.viewDidLoad()
self.title = "RTPagingViewController"
let indicator = UIView(frame: CGRect(x: 0,y: 0,width: self.view.bounds.width / 3,height: 4))
indicator.backgroundColor = UIColor.redColor()
// indicator.autoresizingMask = UIViewAutoresizing.FlexibleBottomMargin
self.titleIndicatorView = indicator
c1.title = "first"
// c1.view.backgroundColor = UIColor.redColor()
c2.title = "second"
// c2.view.backgroundColor = UIColor.greenColor()
c3.title = "third"
// c3.view.backgroundColor = UIColor.grayColor()
self.titleColor = UIColor.blackColor()
self.selectedTitleColor = UIColor.blueColor()
self.controllers = [c1,c2,c3]
self.currentControllerIndex = 0
}
最佳答案
您需要使用 Storyboard ID 创建 View Controller 。
- 在您的 Storyboard中分配 Storyboard ID。
在 viewDidLoad 方法中实例化 View Controller 。
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) let c1 = storyboard.instantiateViewControllerWithIdentifier("FirstViewController") let c2 = storyboard.instantiateViewControllerWithIdentifier("SecondViewController") let c3 = storyboard.instantiateViewControllerWithIdentifier("ThirdViewController")
放入您的 RTPagingViewController。
self.controllers = [c1,c2,c3]
关于ios - 如何用 Storyboard 实现 RTPagingViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34988954/