I have 2 view controller classes. I want to call a method of ViewController2 from ViewController, but the console gives me this error:
fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)
Here is my method in the ViewController class:
class ViewController: UIViewController,CLLocationManagerDelegate,MKMapViewDelegate {
@IBAction func testButton(sender: AnyObject) {
ViewController2().setText("It's a Test!")
}
}
And here is some code from ViewController2:
class ViewController2: UIViewController {
@IBOutlet weak var directionsTextField: UITextView!
func setText(var fieldText:String){
directionsTextField.text = directionsTextField.text + "\n \n" + fieldText
}
}
I'd be glad for every help! :-)
Thank you in advance :)
EDIT:
I also get this:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
on the setText method...
Seems like directionsTextField isn't yet there maybe(??)
UIViewControllersare related (segue, etc) - Victor Sigler