0

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, ... { ... }.

Community
  • 1
  • 1
yerpy
  • 1,366
  • 3
  • 17
  • 44
  • 1
    how do you want to presend view controller on cell? that does not make any sense, think again if what are you doing is what you really want – Lu_ Mar 30 '17 at 11:51
  • Have you followed this thread? http://stackoverflow.com/questions/22904164/presentviewcontroller-from-custom-tablecell-in-xib/22904272#22904272 – NeverHopeless Mar 30 '17 at 11:52
  • @Lu_ .Xib files contains your custom cells - u might use them in few controllers without creating new cells all the time. I would like to send information from one of my controller via `UIActivityViewController`. / @NeverHopeless yes i did, even with this line `dequeueReusableCellWithIdentifier` it does not help - same error. – yerpy Mar 30 '17 at 11:53
  • @NeverHopeless please edit your answer with telling ppl to add the protocol to the header of class. – yerpy Mar 30 '17 at 12:02

0 Answers0