swift - 错误:执行被中断,原因:信号 SIGABRT。在快速的操场上
问题描述
当我尝试在 Xcode 中运行我的游乐场时出现此错误:
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 中的错误吗?还是我的代码有问题?
解决方案
在loadView方法中重新排序代码。在添加约束之前向上移动addSubview
view.addSubview(subtitleLabel)
view.addSubview(titleLabel)
NSLayoutConstraint.activate([
titleLabel.bottomAnchor.constraint(equalToSystemSpacingBelow: subtitleLabel.topAnchor, multiplier: 10)
])
self.view = view
错误将消失。
推荐阅读
- javascript - 在javascript中设置后台计时器
- firebase - 取消订阅 FCM 中某个主题的所有用户
- javascript - 反应瓶颈文本输入输入字段
- python - 如何在 Visual Studio (2019) for Python 中禁用滚动条旁边的代码预览/映射
- excel - Angular 2+将特定表导出到excel
- python - 如何为控制多个散景图形添加一个图例?
- c++ - 无法将(外部)Boost 库加载到项目中
- javascript - 如何阻止 ajax 调用刷新我的页面?
- java - 我应该使用什么数据存储来在我的应用程序中存储歌词?
- javascript - Firefox 忽略 SVG 中的内联 CSS,chrome 显示它