【问题标题】:Getting SIGABRT when using SnapKit library使用 SnapKit 库时获取 SIGABRT
【发布时间】:2016-05-30 17:25:20
【问题描述】:

我有以下代码:

//  ViewController.swift
//  Copypasta Keyboard
//
//  Created by vroy on 5/30/16.
//  Copyright © 2016 vroy. All rights reserved.
//

import UIKit
import SnapKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.


        let thankYouMessage = UILabel()
        thankYouMessage.text = "Thank You for Installing the Keyboard."
        thankYouMessage.textAlignment = .Center
        thankYouMessage.numberOfLines = 1


        thankYouMessage.snp_makeConstraints { (make) -> Void in
              //The program crashes if either of the following two lines are uncommented.
              make.top.left.right.equalTo(0) 
              make.height.equalTo(self.view.snp_height).multipliedBy(0.2)
        }


        self.view.addSubview(thankYouMessage)


    }

}

如果两行之一:

make.top.left.right.equalTo(0) 

make.height.equalTo(self.view.snp_height).multipliedBy(0.2)

执行我得到一个 SIGABRT 错误:

我使用的是 SnapKit 库版本 0.19.0

我该怎么办?

【问题讨论】:

    标签: ios snapkit


    【解决方案1】:

    您需要在进行约束之前添加子视图。所以把代码改成这样:

        let thankYouMessage = UILabel()
        thankYouMessage.text = "Thank You for Installing the Keyboard."
        thankYouMessage.textAlignment = .Center
        thankYouMessage.numberOfLines = 1
    
        self.view.addSubview(thankYouMessage)
    
     thankYouMessage.snp_makeConstraints { (make) -> Void in
                  //The program crashes if either of the following two lines are uncommented.
                  make.top.left.right.equalTo(0) 
                  make.height.equalTo(self.view.snp_height).multipliedBy(0.2)
            }
    

    【讨论】:

      猜你喜欢
      • 2012-03-21
      • 2023-03-05
      • 2013-10-23
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多