prepareForSegue not called in embedded segue

旧城冷巷雨未停 提交于 2019-12-12 07:26:57

问题


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?


回答1:


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.




回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/20442557/prepareforsegue-not-called-in-embedded-segue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!