2016-01-25 33 views
0

我在我的應用程序中使用了RTPagingViewController,我使用了目標c,並用橋接將它鏈接到我的swift項目。 它和它的演示一樣。 有一個問題,當我滾動我的視圖,編譯視圖控制器的代碼,例如,視圖確實加載觸發,但我的故事板和連接到ViewControllers的UIViewContollers不顯示我設計的。 所以我不能用故事板設計我的應用程序,我應該以編程的方式來完成。 我該如何解決這個問題?如何在故事板中實現RTPagingViewController?

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 



} 

}

回答

1

你需要創建一個使用故事板ID的視圖 - 控制。

  • 在故事板中分配故事板ID。
    Storyboard id
  • 實例化在viewDidLoad方法的視圖控制器。

    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]