How can I call a function from a UIButton class in another file to my ViewController Class in Swift 2?

Hello. I'm using PaintCode 2 to generate code, from my Sketch 3 drawings, for my UIButtons, but I'm haveing trouble calling SinButtonFC.UpdateSin(), line 20. The code results in the following error; Use of instance member 'UpdateSin' on type 'SinButtonFC'; did you mean to use a value of type 'SinButtonFC' instead? I'm not sure what this error means, so any help will be greatly appreciated.

FlashCardVC.Swift

import UIKit

class FlashCardsVC: UIViewController {
    @IBOutlet weak var lblAngleMeasurement: UILabel!
    override func viewDidLoad() {
        /
    }
    override func didReceiveMemoryWarning() {
        /
    }
    func Update() {
        sinTitle = "Sin"
        CosTitle = "Cos"
        TanTitle = "Tan"
        CSCTitle = "CSC"
        SecTitle = "Sec"
        CotTitle = "Cot"
        RadianTitle = "Radian"

        SinButtonFC.UpdateSin()
    }

    @IBAction func btnHideAll(sender: UIButton) {
        Update()
    }
    @IBAction func LeftSwipeGesture(sender: UISwipeGestureRecognizer) {
        ArrayIndex += 1
        if ArrayIndex > 16 {
            ArrayIndex = 0
        }
        Update()
        self.lblAngleMeasurement.text = "Angle measure of \(Angles[ArrayIndex])º"
    }
    @IBAction func RightSwipeGesture(sender: UISwipeGestureRecognizer) {
        ArrayIndex -= 1
        if ArrayIndex < 0 {
            ArrayIndex = 16
        }
        Update()
        self.lblAngleMeasurement.text = "Angle measure of \(Angles[ArrayIndex])º"
    }
}


SinButtonFC.Swift(This is a file where I call the coustom class SinButtonFC for the UIButton)

import UIKit

var isPressedSin: Bool = false
var sinTitle: String = "Sin"

class SinButtonFC: UIButton {
    override func drawRect(rect: CGRect) {
        StyleKitUC.drawSinCanvas(sinIsPressed: isPressedSin, sinTitle: sinTitle)
    }
  
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        isPressedSin = true
        self.setNeedsDisplay()
    }
    override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
        isPressedSin = false
        self.setNeedsDisplay()
        /
        if sinTitle == "Sin" {
            sinTitle = "\(Answers[ArrayIndex][0])"
        } else if sinTitle == "\(Answers[ArrayIndex][0])" {
            sinTitle = "Sin"
          
        }
      
    }
    func UpdateSin() {
        self.setNeedsDisplay()
    }
}
Answered by rsharp in 149288022

You need to be working with an instance of type SinButtonFC. Your code on line 20 is assuming UpdateSin is a class method. Your view controller will need an instance variable (perhaps an IBOutlet) to represent your button.


Also, review best practices for naming functions and instance variables; they should begin with a lowercased letter.

Accepted Answer

You need to be working with an instance of type SinButtonFC. Your code on line 20 is assuming UpdateSin is a class method. Your view controller will need an instance variable (perhaps an IBOutlet) to represent your button.


Also, review best practices for naming functions and instance variables; they should begin with a lowercased letter.

How can I call a function from a UIButton class in another file to my ViewController Class in Swift 2?
 
 
Q