mardi 9 juin 2015

If statements for code generated buttons, Swift

I have read a lot on Staked Overflow and watched youtube videos about generating buttons with code, but I can't figure out how to have an if statement based off the button.

I have:

var btn = UIButton(frame: CGRectMake(50, 50, 150, 20));
        btn.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal);
        btn.setTitle("My Button Text!!", forState:UIControlState.Normal);
        btn.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside);
        self.view.addSubview(btn);

     func buttonTapped(sender: UIButton!) {
        println("Button Tapped!!!")
    }

But rather than printing "Button Tapped!!!" I get a "SIGABART" error. How could I use an if statement instead of a function one? Is there a better way to wright this function statement?

Aucun commentaire:

Enregistrer un commentaire