4

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

Sam Luther
  • 998
  • 3
  • 13
  • 34
  • You should see the log in your table view controller class, but only after you execute the segue (by touching a cell if that's where you made the segue from). – rdelmar Dec 07 '13 at 17:08
  • Possible duplicate of [Using container view as a Dashboard](http://stackoverflow.com/questions/25664299/using-container-view-as-a-dashboard) – Fattie May 22 '16 at 20:15
  • is this simple ........ http://stackoverflow.com/a/25991836/294884 – Fattie May 22 '16 at 20:15
  • simple intro to container views if needed http://stackoverflow.com/a/23403979/294884 – Fattie May 22 '16 at 20:16

3 Answers3

15

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

Community
  • 1
  • 1
Fattie
  • 30,632
  • 54
  • 336
  • 607
2

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.

Greg
  • 24,353
  • 5
  • 47
  • 60
  • Hi Greg, there is a connection between the table view controller and other views on the right but I don't see the log for prepareForSegue when I hit the row. – Sam Luther Dec 07 '13 at 15:29
  • It's happened because you control dragged from table view controller to the other view controller. You should control drab from ROW to other VC. Remove this segue and try again. – Greg Dec 07 '13 at 15:49
  • No, I did not drag from the table view to the others, I did in fact control click from each row to the view it's segue'ing to. I confirmed this by clicking on the segue and the row I'm segue'ing from gets selected – Sam Luther Dec 09 '13 at 17:48
  • To summarize: I have a prepareForSegue which appears to fire and logs NSLog(@"LogFrameViewController") in LogFrameViewController. I have a prepareForSegue in TableViewController that does not log or appear to fire – Sam Luther Dec 09 '13 at 18:03
  • @SamLuther see extended post. – Greg Dec 09 '13 at 18:33
  • Hi Greg, the segue style is "Modal". I'm confused by "could be that you haven't add UINavigationController on the view hierarchy" – Sam Luther Dec 09 '13 at 18:39
  • I mean that you haven't got navigation controller your push segue won't work. – Greg Dec 09 '13 at 18:43
  • If you look at the table in the screenshot, if I click on any row it segues to its assigned view. So the segue works correct? What I don't see is evidence of prepareForSegue being called – Sam Luther Dec 09 '13 at 18:46
  • Can you, just for testing, add to your TableViewController didSelectRowAtIndexPath: method [self performSegueWithIdentifier:@"YOUR SEGUE IDENTIFIER" sender:NIL]; – Greg Dec 09 '13 at 18:47
  • Greg, unbelievably stupidity on my part, the table view controller's delegate was not set to my custom controller. I'm very sorry to have wasted you time and appreciate your help – Sam Luther Dec 09 '13 at 19:10
0

Other than what's already discussed, you should make sure you aren't ignoring segue identifier in following delegate call.

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
Mojtaba
  • 5,694
  • 4
  • 23
  • 38