boristhescot
boristhescot

Reputation: 129

Accessing Button Target Throwing Error

With the code below I get an error when I press the button. I'm not sure why.The error is unrecognized selector sent to instance and terminates with "terminating with uncaught exception of type NSException." Any help sure is appreciated. Thanks

class WordSearchWindow: UIViewController {

let boardsize = 10

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(false)
    buttonGridder()
}

func buttonGridder() {
    for x in 0..<self.boardsize {
        for y in 0..<self.boardsize{
            let sizer = ButtonGrid.frame.width
            let buttonSize:CGFloat = sizer / CGFloat(self.boardsize)
            let letterButton = WordButton(column: x, row: y, buttonSize: buttonSize, buttonMargin: 0)
            letterButton.addTarget(self, action: "letterFirst", forControlEvents: .TouchDown)
            letterButton.addTarget(self, action: "letterSecond", forControlEvents: .TouchUpInside)
            self.ButtonGrid.addSubview(letterButton)
        }
    }
}

func letterFirst(sender: WordButton) {
    print("hello1")
}

func letterSecond(sender: WordButton) {
    print("hello2")
}
}

Upvotes: 0

Views: 22

Answers (1)

AAA
AAA

Reputation: 1977

Try this :

letterButton.addTarget(self, action: "letterFirst:", forControlEvents: .TouchDown)
letterButton.addTarget(self, action: "letterSecond:", forControlEvents: .TouchUpInside)

Add : in the action

Upvotes: 1

Related Questions