【问题标题】:error: Execution was interrupted, reason: signal SIGABRT. In swift playgrounds错误:执行被中断,原因:信号 SIGABRT。在快速的操场上
【发布时间】:2020-08-21 10:38:40
【问题描述】:

当我尝试在 Xcode 中运行 Playground 时出现此错误:

error: Execution was interrupted, reason: signal SIGABRT.
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.

这是我的游乐场代码:

import UIKit
import PlaygroundSupport

class MyViewController : UIViewController {
    override func loadView() {
        let view = UIView()
        view.backgroundColor = .white

        let titleLabel = UILabel()
        titleLabel.frame = CGRect(x: 150, y: 200, width: 200, height: 20)
        titleLabel.text = "Title"
        titleLabel.textColor = .black

        let subtitleLabel = UILabel()
        subtitleLabel.text = "Subtitle"
        subtitleLabel.textColor = .gray
        subtitleLabel.frame = CGRect(x: 150, y: 200, width: 200, height: 20)

        NSLayoutConstraint.activate([
            titleLabel.bottomAnchor.constraint(equalToSystemSpacingBelow: subtitleLabel.topAnchor, multiplier: 10)
        ])

        view.addSubview(subtitleLabel)
        view.addSubview(titleLabel)
        self.view = view
    }
}
PlaygroundPage.current.liveView = MyViewController()

如何解决此错误?这是 Xcode 中的错误吗?还是我的代码有问题?

【问题讨论】:

    标签: swift xcode uiview swift-playground


    【解决方案1】:

    loadView 方法中重新排序代码。在添加约束之前向上移动 addSubview

    view.addSubview(subtitleLabel)
    view.addSubview(titleLabel)
    
    NSLayoutConstraint.activate([
                titleLabel.bottomAnchor.constraint(equalToSystemSpacingBelow: subtitleLabel.topAnchor, multiplier: 10)
            ])
    
    self.view = view
    

    错误会消失。

    【讨论】:

      猜你喜欢
      • 2021-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-20
      • 2017-02-25
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      相关资源
      最近更新 更多