简体   繁体   English

为什么我的情节提要中的视图不显示(快速)?

[英]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.

相关问题 为什么选项卡栏没有显示在我的视图控制器上? - Why doesn't the tab bar show up on my view controllers? 为什么我的视图类没有显示在情节提要中? - Why does my view class not show up in storyboard? 为什么我的导航栏不显示? - Why my navbar doesn't show up? 为什么 Main.storyboard 不显示? - Why Main.storyboard doesn't show? iOS Swift-为什么图像视图没有出现在情节提要中的默认字幕样式TableCellView中,所以为什么它与标签不同 - IOS Swift - Why doesn't the image view appear in the default subtitle style TableCellView in the storyboard why is it different then the labels 为什么我无法使用“自动布局”使用渐变子图层来放置视图? 没有出现 - Why am I unable to position my view with a gradient sublayer with Auto Layout? It doesn't show up 表格视图不显示数据,为什么? (快速3) - Table View doesn't show Data, why? (Swift 3) 为什么我的Swift Playground中没有任何显示? - Why won't anything show up in my Swift Playground? 为什么我的垂直编程滚动视图在 Swift 中不起作用 - Why doesn't my vertical programmatic scroll view work in Swift 为什么我的标签栏没有显示在模拟器中? - Why doesn't my Tab Bar show up in the simulator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM