I am having trouble with Xcode; it returns a “Could not insert new action connection” message when I try to establish a new action connection between storyboard and the view controller.
Here is what the error message looks like.
mine worked using
@IBAction func tappedRed(sender: AnyObject) {
view.backgroundColor = UIColor.redColor()
}
@IBAction func tappedBlue(sender: AnyObject) {
view.backgroundColor = UIColor.blueColor()
}
@IBAction func tappedGreen(sender: AnyObject) {
view.backgroundColor = UIColor.greenColor()
says cannot find ‘UIcolor’ every time i type .red .blue .green
Hey guys,
For the error “Could not insert new action connection” - Make sure that you do not have any other actions referencing to the view controller. Here is a great link to solve your problem. ios - Could not insert new outlet connection: Could not find any information for the class named - Stack Overflow
@pdenlinger - Interesting how yours did not work using the .red .blue .green properties on UIColor. This is my code and it ran fine.
@IBAction func blueBackground(_ sender: Any) {
view.backgroundColor = UIColor.blue
}
@IBAction func greenBackground(_ sender: Any) {
view.backgroundColor = UIColor.green
}
@IBAction func redBackground(_ sender: Any) {
view.backgroundColor = UIColor.red
}
My solution using a single function and a switch statement:
class ViewController: UIViewController {
@IBAction func changeColor(_ sender: UIButton!) {
let currentSelection = sender.currentTitle!
print(currentSelection)
switch currentSelection {
case "Red":
view.backgroundColor = UIColor.red
case "Blue":
view.backgroundColor = UIColor.blue
case "Green":
view.backgroundColor = UIColor.green
default:
print ("Error")
}
}
2 Likes