5ive
5ive

Reputation: 273

UIButtons won't click in simulator swift

Sorry if this is a dumb question. I just can't find why the UIbuttons are not working. They were working for awhile. Not sure what happened.

import UIKit  

class ViewController: UIViewController 
{

@IBOutlet weak var display: UILabel!

var userIsInTheMiddleOfTypingNumber = false

@IBAction func appendDigit(sender: UIButton) {
    let digit = sender.currentTitle!
    if userIsInTheMiddleOfTypingNumber {
        display.text = display.text! + digit
    }
    else {
        display.text = digit
        userIsInTheMiddleOfTypingNumber = true
    }
}

var operandStack = Array<Double>()

@IBAction func enter() {
    userIsInTheMiddleOfTypingNumber = false
    operandStack.append(displayValue)
    println("operandStack = \(operandStack)")
}

var displayValue: Double {
    get {
        return NSNumberFormatter().numberFromString(display.text!)!.doubleValue
    }
    set {
        display.text = "\(newValue)"
        userIsInTheMiddleOfTypingNumber = false
    }
  }
}

Upvotes: 0

Views: 1183

Answers (1)

eliasRuizHz
eliasRuizHz

Reputation: 354

chances are that after having made the IBAction connect you would change the name of the function, which untying its storyboard to your ViewController, if this were the case consult the storyboard and unlink the above, then should link to new.

Also I suggest you check this out:

@IBAction func enter(sender: AnyObject) {}

or

@IBAction func enter(sender: UIButton!) {}

Upvotes: 1

Related Questions