I have two ViewControllers, FirstViewController
and SecondViewController
. Both have an own Swift file, FirstViewController.swift
and SecondViewController.swift
.
FirstViewController.swift
contains:
class FirstViewController: UIViewController {
@IBAction func callFunctionInOtherClass(sender: AnyObject) {
// Call "func showAlert" in SecondViewController when clicking the UIButton in FirstViewController
}
}
SecondViewController.swift
contains:
class SecondViewController: UIViewController {
@IBOutlet weak var textField: UITextField!
func showAlert(sender: AnyObject) {
let alert = UIAlertView(title: "Working!", message: "This function was called from FirstViewController!\nTextField says: \(textField.text!)", delegate: nil, cancelButtonTitle: "Okay")
alert.show()
}
}
I want to be able to call the func showAlert()
in SecondViewController
when taping on the UIButton
in FirstViewController
.
I've already spent many nights to find a solution but none worked. Does anybody know what to do to reach this goal?
I uploaded a sample Xcode project here: CallFuntionInOtherClassX | filedropper.com
P.S.: Of course, I could post some code and explain what error I get, but I think it's not reasonable because I really don't know how to do that.