• <bdo id='7RAAZ'></bdo><ul id='7RAAZ'></ul>

    <tfoot id='7RAAZ'></tfoot>
  1. <legend id='7RAAZ'><style id='7RAAZ'><dir id='7RAAZ'><q id='7RAAZ'></q></dir></style></legend>
    1. <i id='7RAAZ'><tr id='7RAAZ'><dt id='7RAAZ'><q id='7RAAZ'><span id='7RAAZ'><b id='7RAAZ'><form id='7RAAZ'><ins id='7RAAZ'></ins><ul id='7RAAZ'></ul><sub id='7RAAZ'></sub></form><legend id='7RAAZ'></legend><bdo id='7RAAZ'><pre id='7RAAZ'><center id='7RAAZ'></center></pre></bdo></b><th id='7RAAZ'></th></span></q></dt></tr></i><div id='7RAAZ'><tfoot id='7RAAZ'></tfoot><dl id='7RAAZ'><fieldset id='7RAAZ'></fieldset></dl></div>

    2. <small id='7RAAZ'></small><noframes id='7RAAZ'>

    3. 出现异常:“无法使用未准备好约束的视图层次结构设置布局"

      时间:2023-09-10

      <small id='TBFYB'></small><noframes id='TBFYB'>

        <i id='TBFYB'><tr id='TBFYB'><dt id='TBFYB'><q id='TBFYB'><span id='TBFYB'><b id='TBFYB'><form id='TBFYB'><ins id='TBFYB'></ins><ul id='TBFYB'></ul><sub id='TBFYB'></sub></form><legend id='TBFYB'></legend><bdo id='TBFYB'><pre id='TBFYB'><center id='TBFYB'></center></pre></bdo></b><th id='TBFYB'></th></span></q></dt></tr></i><div id='TBFYB'><tfoot id='TBFYB'></tfoot><dl id='TBFYB'><fieldset id='TBFYB'></fieldset></dl></div>
            <legend id='TBFYB'><style id='TBFYB'><dir id='TBFYB'><q id='TBFYB'></q></dir></style></legend>
          • <tfoot id='TBFYB'></tfoot>
              <bdo id='TBFYB'></bdo><ul id='TBFYB'></ul>

                  <tbody id='TBFYB'></tbody>

              1. 本文介绍了出现异常:“无法使用未准备好约束的视图层次结构设置布局"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                在我的故事板应用程序中,我尝试向界面添加额外的 UITextField.但我得到了标题所说的例外.我使用 SwiftAutoLayout 库.这是我的代码:

                In my storyboard application I try to add extra UITextField to interface. But I get the exception that title says. I use SwiftAutoLayout library. Here is my code:

                // MARK: - IBOutlets
                
                @IBOutlet weak var passwordTextField: UITextField!
                
                // MARK: - Properties
                
                let userIdTextField = UITextField()
                
                // MARK: - Lifecycle
                
                override func viewDidLoad() {
                    super.viewDidLoad()
                
                    self.passwordTextField.keyboardType = .NumberPad
                
                    if getCurrentUserId() == nil {
                        self.view.addSubview(userIdTextField)
                        userIdTextField.setTranslatesAutoresizingMaskIntoConstraints(false)
                        self.view.addConstraints([userIdTextField.al_leading == passwordTextField.al_leading,
                            userIdTextField.al_trailing == passwordTextField.al_trailing,
                            userIdTextField.al_top == passwordTextField.al_bottom + 8])
                        userIdTextField.placeholder = "Enter User Id..."
                    }
                }
                

                推荐答案

                在绑定任何约束之前尝试将 passwordTextField 添加到其父视图.

                Try adding passwordTextField to its superview before binding any constraints to it.

                UPD(感谢 @vmeyer 和 @MacMark):请注意,在 viewDidLoadviewWillAppear/viewDidAppear 但在 updateViewConstraints 或 viewWillLayoutSubviews 因为视图层次结构可能没有为此操作做好准备.

                UPD (thanks @vmeyer and @MacMark): please notice that it's safer to add constraints not in viewDidLoad or viewWillAppear/viewDidAppear but in updateViewConstraints or viewWillLayoutSubviews since the view hierarchy might be unprepared for this operation.

                这篇关于出现异常:“无法使用未准备好约束的视图层次结构设置布局"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何使用自动布局在 MKAnnotation 中显示多行? 下一篇:具有自动布局和部分重新加载的 UITableViewHeaderFooterView 子类不能很好地协同工作

                相关文章

                <small id='ndLW1'></small><noframes id='ndLW1'>

                • <bdo id='ndLW1'></bdo><ul id='ndLW1'></ul>
                <legend id='ndLW1'><style id='ndLW1'><dir id='ndLW1'><q id='ndLW1'></q></dir></style></legend>
                <i id='ndLW1'><tr id='ndLW1'><dt id='ndLW1'><q id='ndLW1'><span id='ndLW1'><b id='ndLW1'><form id='ndLW1'><ins id='ndLW1'></ins><ul id='ndLW1'></ul><sub id='ndLW1'></sub></form><legend id='ndLW1'></legend><bdo id='ndLW1'><pre id='ndLW1'><center id='ndLW1'></center></pre></bdo></b><th id='ndLW1'></th></span></q></dt></tr></i><div id='ndLW1'><tfoot id='ndLW1'></tfoot><dl id='ndLW1'><fieldset id='ndLW1'></fieldset></dl></div>
                <tfoot id='ndLW1'></tfoot>