简体   繁体   中英

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. I am using a custom UITableViewCell class called chillerCell . 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)"

I made my own Event class, and yes, event.eventName and event.eventDescription are of type String and are not Nil .

Edit: I forgot to mention, my boldLabel and italicLabel are not plain text, but attributed text.

Try this, it would work if event object having eventName & eventDescription as String:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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