[英]why the view in my storyboard doesn't show up (Swift)?
I has one initial view controller in my story board here is the code: 我的故事板上有一个初始视图控制器,代码如下:
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()
}
}
in the customUI class I have this code : 在customUI类中,我有以下代码:
import UIKit
class customUI : UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
}
Then I create another viewController in storyboard and set the class to be customUI class. 然后,我在情节提要中创建另一个viewController并将该类设置为customUI类。 Then I choose its background color in storyboard to be blue.
然后,我在情节提要中选择其背景颜色为蓝色。
Then I run the simulator, and click on the textField. 然后,我运行模拟器,然后单击textField。 it loads the plain grey area instead of the blue background that I have set.
它会加载纯灰色区域而不是我设置的蓝色背景。
Why? 为什么? how to fix this?
如何解决这个问题? I'm new to UI in Xcode.
我是Xcode中的UI新手。
some people talking about this issue in Objective-C but I know only swift, please give me detail explanation in swift. 有些人在Objective-C中谈论这个问题,但我只知道迅速,请迅速给我详细解释。
When you create the customview
object it does not have any connection with your storyboard, you need to do: 创建
customview
对象时,该对象与情节提要板没有任何关系,您需要执行以下操作:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let customview = storyboard.instantiateViewControllerWithIdentifier("SIDCustomUI") as! customUI
where SIDCustomUI
is Storyboard ID
for your ViewController
其中
SIDCustomUI
是您的ViewController
Storyboard ID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.