gpt4 book ai didi

ios - 类 "View controller"没有初始化程序

转载 作者:行者123 更新时间:2023-11-29 01:25:55 25 4
gpt4 key购买 nike

我收到“类“ View Controller ”没有初始化程序”错误。

我尝试初始化所有变量,但错误不断出现。

听到的是代码:

import UIKit


class ViewController: UIViewController {

@IBOutlet weak var Screen: UILabel!
var primerNum = Float()
var segundoNum = Float()
var result = Float()
var operat = ""
var isTypingNumber = false
var num: Int?
var coma: Int?

@IBAction func num(sender: AnyObject) {
var num = sender.currentTitle
if isTypingNumber == true {
Screen.text = Screen.text! + num!!
} else {
Screen.text = num
}
isTypingNumber = true
}

@IBAction func coma(sender: AnyObject) {
var coma = sender.currentTitle
Screen.text = Screen.text! + coma!!
}

@IBAction func operat(sender: AnyObject) {
operat = sender.currentTitle!!
primerNum = (Screen.text! as NSString).floatValue

}

@IBAction func igual(sender: AnyObject) {
segundoNum = (Screen.text! as NSString).floatValue
if operat == "+" {
result = primerNum + segundoNum
} else if operat == "-" {
result = primerNum - segundoNum
} else if operat == "x" {
result = primerNum * segundoNum
} else if operat == "/" {
result = primerNum / segundoNum
} else if operat == "%" {
result = (primerNum * segundoNum) / 100
}
Screen.text = "\(result)"
}

@IBAction func clear(sender: AnyObject) {
primerNum = 0
segundoNum = 0
result = 0
Screen.text = "\(result)"
}
}

提前致谢!

最佳答案

这看起来是正确的,并且在本地也可以很好地编译。您是否尝试过清理和重建(命令-shift-K,然后命令-b)?或者,重新启动 Xcode。

关于ios - 类 "View controller"没有初始化程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34024893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com