简体   繁体   English

Swift线程1:当我尝试更改uilabel.text时为EXC_BAD_INSTRUCTION

[英]Swift Thread 1: EXC_BAD_INSTRUCTION when I try to change a uilabel.text

I know there are a lot of Stack Overflow questions like this out there, but none of the answers I can find work for me. 我知道这里有很多类似Stack Overflow的问题,但是找不到我能找到的答案。 I am using a custom UITableViewCell class called chillerCell . 我正在使用一个名为chillerCell的自定义UITableViewCell类。 Here is its code: 这是它的代码:

import UIKit

class chillerCell: UITableViewCell {

    @IBOutlet weak var iconLabel: UILabel!
    @IBOutlet weak var boldLabel: UILabel!
    @IBOutlet weak var italicLabel: UILabel!

    func configureCellWithEvent(event: Event){
        boldLabel.text = "\(event.eventName)"
        italicLabel.text = "\(event.eventDescription)"
    }
}

I get the Thread 1 runtime error on the line boldLabel.text = "\\(event.eventName)" 我在一行boldLabel.text = "\\(event.eventName)"上得到线程1运行时错误

I made my own Event class, and yes, event.eventName and event.eventDescription are of type String and are not Nil . 我创建了自己的Event类,是的, event.eventNameevent.eventDescription的类型为String ,而不是Nil

Edit: I forgot to mention, my boldLabel and italicLabel are not plain text, but attributed text. 编辑:我忘了提一下,我的boldLabel和italicLabel不是纯文本,而是属性文本。

Try this, it would work if event object having eventName & eventDescription as String: 尝试此操作,如果将eventName和eventDescription作为字符串的事件对象可以工作:

func configureCellWithEvent(event: Event){
    var attributedString = NSMutableAttributedString(string:"(event.eventName)") and boldLabel.text = attributedString
    boldLabel.text = attributedString
    italicLabel.text = attributedString
}

删除标签并再次创建其他标签,这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM