简体   繁体   中英

Calling function on subclass of UILabel

I can't really understand why I am getting this error when I call a function on a subclass of UILabel. I have in AppDelegate

class CascadingLabel: UILabel {
func cascade(){
    DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
            self.alpha = 1
        }
    }
func initializeText(){
    print("[OUT21] Init")
}
}

In ViewController,

@IBOutlet weak var Intro1: CascadingLabel!
 func initializeText(){
    Intro1.initializeText() //Here I am getting error!
}
override func viewDidLoad() {
    super.viewDidLoad()
    print("[OUT21] OpeningScreen opened")
    initializeText()
}

The app crashes, yielding error:

Thread 1: EXC_BAD_ACCESS (code=2, address=0x1b3900ec8)

UPDATE ANSWER: Thanks to @ChristianAbella for the answer here. I didn't indicate the class in the Storyboard.

I think you are getting following error

在此处输入图片说明

Everything is fine just assign your class name to UILabel in storyboard

在此处输入图片说明

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