I am trying to present another view controller from the .xib
file, but it does not let me. I am getting an error inside the function : func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath)
That's how i declare the cell
:
let cell = Bundle.main.loadNibNamed("CustomViewCell", owner: self, options: nil)?.first as! CustomViewCell
and then I call :
cell.delegate = self
This call couse an error : Cannot assign value of type "MyViewController" to type "shareInfo?"
Then in my .xib
file i do have :
protocol shareInfo : NSObjectProtocol {
func loadNewScreen(controller: UIViewController) -> Void
}
Inside the class CustomViewCell
:
weak var delegate: shareInfo?
and then the method :
@IBAction func shareLocation(_ sender: Any) {
let vc = UIActivityViewController(activityItems: [testLabel.text!], applicationActivities: nil)
if delegate?.responds(to: Selector(("loadNewScreen"))) != nil {
delegate?.loadNewScreen(controller: vc)
}
}
Any one knows whats going on ?
Thanks in advance!
EDIT
Also I do have this function in MyViewController
func loadNewScreen(controller: UIViewController) {
self.present(controller, animated: true) { () -> Void in
};
}
I was following this solution
SOLUTION
Ok, I've solved my problem -> protocol has to be added into MyViewController : ... , shareInfo, ... { ... }
.