2015-11-02 102 views
0

我已經在這裏我的故事板上的一個初始視圖控制器代碼:爲什麼我的故事板中的視圖不顯示(Swift)?

import UIKit 

class ViewController: UIViewController { 


@IBOutlet weak var textField: UITextField! 

override func viewDidLoad() { 
    super.viewDidLoad() 

    let customview = customUI() 

    textField.inputView = customview.view 
} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 

} 

} 

在customUI類我有這樣的代碼:

然後我在故事板創建另一個的viewController和設置類是customUI類。然後,我選擇故事板中的背景顏色爲藍色。

然後我運行模擬器,然後單擊textField。它會加載純灰色區域,而不是我設置的藍色背景。

爲什麼?如何解決這個問題?我是Xcode的新用戶界面。

有些人在Objective-C中討論這個問題,但我只知道很快,請迅速給我詳細的解釋。

+1

我想你應該看看這個帖子:http://stackoverflow.com/questions/27276561/swift-adding-a-view-controller-as-a-subview-in-another-view-controller – Laffen

回答

2

當您創建customview對象不與你的故事板的任何連接,你需要做的:

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
let customview = storyboard.instantiateViewControllerWithIdentifier("SIDCustomUI") as! customUI 

其中SIDCustomUIStoryboard IDViewController