I'm sorry i have bad eng skill.
i want access IBOutlet in another class. i found many question in stackoverflow, but all answer not working in my code
firstly this is my code.
ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var MainViewController: UIView! = nil
@IBOutlet var LyricsViewController: UIView! = nil
@IBOutlet var ListViewController: UIView! = nil
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
showMainViewController()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func showMainViewController(){
MainViewController.alpha = 1
LyricsViewController.alpha = 0
ListViewController.alpha = 0
}
func showLyricsViewController(){
MainViewController.alpha = 0
LyricsViewController.alpha = 1
ListViewController.alpha = 0
}
func showListViewController(){
MainViewController.alpha = 0
LyricsViewController.alpha = 0
ListViewController.alpha = 1
}
}
and i want access ViewController's function in this class
SecondViewController.swift
import UIKit
class SecondViewController : UIViewController{
@IBOutlet weak var menuButton: UIButton!
var listBoolean = false
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func LinkListView(sender: AnyObject) {
if(listBoolean == false){
ViewController().showListViewController()
listBoolean = true
}
else{
ViewController().showMainViewController()
listBoolean = false
}
}
}
func showMainViewController() is work in ViewController's viewDidLoad() but error in SecondViewController with this setance
fatal error : unexpectedly found nil while unwrapping an Optional value
how can i fix this problem?