我正在尝试通过情节提要添加多个卡片视图。我将代码与 IBOutlet 链接起来,并添加标题视图和详细信息视图。一旦我运行应用程序并转到 CardViews,应用程序崩溃给我“线程 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)”第一个 CardView (grammarCard) 工作正常,但第二个不 (vocabCard)。
这是代码
import UIKit
进口材料
类 StudyViewController: UIViewController {
@IBOutlet weak var vocabCard: CardView!
@IBOutlet weak var grammarCard: CardView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// Grammar Card Title
let gTitleLabel:UILabel = UILabel()
gTitleLabel.text = "Grammar"
gTitleLabel.textColor = MaterialColor.deepPurple.darken1
grammarCard.titleLabel = gTitleLabel
// Grammar Card Detail
let detailLabel: UILabel = UILabel()
detailLabel.text = "Learn"
detailLabel.numberOfLines = 0
grammarCard.detailView = detailLabel
// Start button
let button: FlatButton = FlatButton()
button.pulseColor = MaterialColor.deepPurple.lighten1
button.pulseScale = false
button.setTitle("Start", forState: .Normal)
button.setTitleColor(MaterialColor.deepPurple.darken1, forState: .Normal)
// Adding Buttons
grammarCard.rightButtons = [button]
//THIS ONE IS FINE
// Do any additional setup after loading the view.
// Vocab Card Title
let vTitleLabel:UILabel = UILabel()
vTitleLabel.text = "Vocabulary"
vTitleLabel.textColor = MaterialColor.deepPurple.darken1
vocabCard.titleLabel = vTitleLabel // Here the issue pops up
// Vocab Card Detail
let vdetailLabel: UILabel = UILabel()
vdetailLabel.text = "Learn the words of "
vdetailLabel.numberOfLines = 0
vocabCard.detailView = vdetailLabel // Here the issue pops up
// Start button
let vbutton: FlatButton = FlatButton()
vbutton.pulseColor = MaterialColor.deepPurple.lighten1
vbutton.pulseScale = false
vbutton.setTitle("Start", forState: .Normal)
vbutton.setTitleColor(MaterialColor.deepPurple.darken1, forState: .Normal)
// Adding Buttons
vocabCard.rightButtons = [vbutton]
}
非常感谢您的先进!