【问题标题】:How do I add multiple Card Views in Material for iOS?如何在 iOS 的 Material 中添加多个卡片视图?
【发布时间】:2016-04-13 10:45:47
【问题描述】:

我正在尝试通过情节提要添加多个卡片视图。我将代码与 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]


}

非常感谢您!

【问题讨论】:

    标签: cosmicmind


    【解决方案1】:

    我没有在代码中看到问题,因此很可能是情节提要中的设置。所以我们在1.39.9 中添加了一个使用两个 CardView 和故事板的示例。您可以在示例/故事板目录中找到它。

    一切顺利!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      • 1970-01-01
      相关资源
      最近更新 更多