L.Vl
L.Vl

Reputation: 113

perform Segue With Identifier from a dynamic collectionViewCell in a tableViewCell of a dynamic tableView, swift

I have in a dynamic tableView, a dynamic collectionView in one of the tableViewCell.

In every collectionViewCell, there is a button which should be the trigger for the segue.

I tried with the following code, but the app crash :

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<Okm.bienController: 0x7fc8b0cfb1a0>) has no segue with identifier 'extend''

The segue identifier in my storyBoard is 'extend'.

 class photoCell: UITableViewCell, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource {
    ...

    func extendFunc(sender : UIButton) {

       bienController().performSegueWithIdentifier("extend", sender: sender.tag)
    }
}


class bienController : UIViewController, UITableViewDelegate, UITableViewDataSource {

...

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "extend" {
            let backItem = UIBarButtonItem()
            backItem.title = ""
            navigationItem.backBarButtonItem = backItem

            let extendView = segue.destinationViewController as! extendController
            extendView.image = image[sender]

        }
    }
}

Do you know how I can do it?

Thank you!!!

EDIT

enter image description here

the term bienController().performSegueWithIdentifier(...) is it correct? Can I call a function of my Controller from a UICollectionCell ?

EDIT

I tried this :

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if tableView == self.tableViewTwo {
            self.segue()
          // self.performSegueWithIdentifier("image", sender: nil)
        }
    }

    func clickExtend(sender:Int){
        print(sender) //print the correct tag!
       self.segue()
    }

    func segue(){
         self.performSegueWithIdentifier("image", sender: nil)
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if segue.identifier == "image" {
            let backItem = UIBarButtonItem()
            backItem.title = ""
            navigationItem.backBarButtonItem = backItem
           // print(sender)

           let extendView = segue.destinationViewController as! extendController
           extendView.image = UIImage(named: "maison")

        }
    }
}

I linked the function clickExtend() with the button of my collectionCell. The segue works when it somes from didSelectRowAtIndexPath, but when I click on the button extend it crashes with the same error : 'Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'image'''

I don't get it..

( I changed the segue identifier for 'image')

Upvotes: 0

Views: 312

Answers (4)

Behdad
Behdad

Reputation: 1629

You have to use delegates. I had this problem before,and I used protocol and delegates to solve It and perform a segue with identifier.

Upvotes: 0

Nate
Nate

Reputation: 188

like Fernando Cani says

try change bienController().performSegueWithIdentifier("name")

to

self.performSegueWithIdentifier("name")

Upvotes: 0

Nate
Nate

Reputation: 188

It looks like the identifier is either not connected properly or its is not set as "extend" because the error message says (has no segue with identifier 'extend')

Upvotes: 0

Fernando Cani
Fernando Cani

Reputation: 69

Check if the segue is coming out of the cell or the viewController. Maybe it is that.

Upvotes: 1

Related Questions