我有一个类ECGView,有一个子类,InjuryView。当我运行代码时,控制台显示“lldb”,并在InjuryView子类的init方法中抛出以下错误:线程1:EXC_BAD_INSTRUCTION(代码= EXC_I386_INVOP,子代码= 0x0)。
我对编程比较陌生,而且我无法弄清楚为什么会抛出这个错误。任何帮助将不胜感激,谢谢!
class ECGView {
var title: String
var normalImage: UIImage
var markedImageByComponents: [MarkedAnatomyComponent]
var steps: [UIImage]
var stepDescriptions: [String]
var sectionNames: [[String]]
var attribution: String
var injuryList: [[InjuryView]]
var numberOfPages: Int = 0
var anatomyOverlay: Bool = false
var currentStep: Int = 0
var section: Bool = true
init(title: String, normalImage: UIImage, markedImageByComponents: [MarkedAnatomyComponent] = [], steps: [UIImage] = [], stepDescriptions: [String] = [], sectionNames: [[String]] = [], attribution: String, injuryList: [[InjuryView]] = []){
self.title = title
self.normalImage = normalImage
self.markedImageByComponents = markedImageByComponents
self.steps = steps
self.stepDescriptions = stepDescriptions
self.sectionNames = sectionNames
self.attribution = attribution
self.injuryList = injuryList
}
}
class InjuryView: ECGView{
var injuryImage: UIImage
var injuryComponents: [MarkedAnatomyComponent]
var injuryTitle: String
var shortInjuryTitle: String
var injuryAttribution: String
var overviewText: String
var findingsText: String
var managementText: String
var otherTitle: String
var otherText: String
var normalToggle: Bool = false
}
此处抛出错误>
init(injuryImage: UIImage = #imageLiteral(resourceName: "Placeholder.jpg"), injuryComponents: [MarkedAnatomyComponent], injuryTitle: String = "", shortInjuryTitle: String = "", injuryAttribution: String, overviewText: String, findingsText: String, managementText: String, otherTitle: String = "", otherText: String = ""){
self.injuryImage = injuryImage
self.injuryComponents = injuryComponents
self.injuryTitle = injuryTitle
self.shortInjuryTitle = shortInjuryTitle
self.injuryAttribution = injuryAttribution
self.overviewText = overviewText
self.findingsText = findingsText
self.managementText = managementText
self.otherTitle = otherTitle
self.otherText = otherText
super.init(title: "", normalImage: #imageLiteral(resourceName: "Blank.png"), attribution: "")
self.title = title
section = false
}
答案 0 :(得分:0)
更改此init
行:
init(title: String, normalImage: UIImage, markedImageByComponents: [MarkedAnatomyComponent] = [], steps: [UIImage] = [], stepDescriptions: [String] = [], sectionNames: [[String]] = [], attribution: String, injuryList: [[InjuryView]] = []){
为:
init(title: String, normalImage: UIImage, markedImageByComponents: [MarkedAnatomyComponent] = [], steps: [UIImage] = [], stepDescriptions: [String] = [], sectionNames: [[String]] = [[]], attribution: String, injuryList: [[InjuryView]] = [[]]){
因为您有这种类型的数组,所以需要使用[[]]
而不是[]
清除它。