Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prepareForSegue not called in embedded segue

I have a table view controller embedded in a container in a view controller.

In both the view and table view controllers prepareForSegue method I put NSLog(@"name of the controller") I see a log for the view controller but not the table view controller. Shouldn't I also see the nslog for my table view's prepareForSegue?

enter image description here

like image 904
Sam Luther Avatar asked Dec 02 '22 21:12

Sam Luther


2 Answers

Exactly - as Greg explains, the embed type of segue is

only called during setup!

This is very confusing. You could say that

"prepareForSegue" is A REALLY BAD NAME!

the name "prepare for segue" only makes sense in the (rare!) case where you are actually "segueing" from one scene to another

In an iOS app container views are commonplace, you have them everywhere, whereas you rarely use an actual "scene segue".

So really, "prepareForSegue" should be called something like:

"Hey, we're setting up all your container views -- you can grab any info you need at this time! Oh, if you happen to be doing a scene segue, you can use this also!"

what about:

containerViewBeingSetUpOhAndAlsoPrepareForSegueIfYouHappenToBeDoingThat:

That's a bit long, but clearer!

It's just one of those weird things about iOS that you have to know, but is never explained anywhere.

Here's a full explanation of using container views for beginners https://stackoverflow.com/a/23403979/294884

like image 132
Fattie Avatar answered Dec 08 '22 14:12

Fattie


In Your Log Frame View Controller prepareForSegue will be called directly after initWithCoder: to prepare your TableViewController. I cannot see your connection between table view controller and another view (view on the right) but I believe it will be called when you hit the row.

//EXTENDED

The other thing could be that you haven't add UINavigationController on the view hierarchy and you set up your segue style to 'push'. Try change style of your segue to 'modal' in attribute inspector. Hope this help.

like image 29
Greg Avatar answered Dec 08 '22 15:12

Greg