Class"查看控制器"没有初始化者

时间:2015-12-01 16:15:15

标签: ios swift initialization

我得到了一个" Class" 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)"
    }
}

提前谢谢!!

1 个答案:

答案 0 :(得分:1)

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