ios - 如何用 Storyboard 实现 RTPagingViewController?

标签 ios objective-c iphone swift

我在我的应用程序中使用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。
    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/

相关文章:

ios - GMSCoordinateBounds 角值 - Google Maps SDK

ios - 是否可以在 Storyboard 中区分左右横向?

ios - 如何在 IOS 中从 google drive V3 API 下载 pdf?

ios - 无法重新启用我的应用中的位置

ios - 上传图片到 Firebase

iphone - iOS : Timer doesn't run when we are scrolling any view

iPhone 开发 - 在 map 上显示两个位置

ios - 改变 Swift 中的 VC 问题。如何在标签栏 Controller 的 View 之间传递数据?

javascript - 基于 scroll(function()) 应用 CSS

c++ - cocos2dx中的类类类型