last day (14 days later) » 

9:21 PM
0
A: Performing segue after sender view controller is dismissed

Mike TaverneBased on a modification to this answer, the following should work: In your storyboard, remove the segue that is triggered by tapping your menu button and goes to Destination. Create a new segue that goes from the Origin view controller to Destination view controller. This segue is going to be m...

 
Thanks, that's interesting - I tried this, and when I dismissed Destination, it went back to Menu, not Origin. To be more specific, I added your code exactly (except my segue name is different) to my IBAction that handles the menu button being tapped to present Destination.
Actually, I misread your comment. The code in your answer should be in the Origin controller? How do I call the Destination segue on Origin? I would generally call the segue in the IBAction of the menu button being pressed, which is obviously hooked up to the Menu controller.
 
@KingTim I've updated my answer to address your questions. Please re-read the entire answer. The solution didn't change, but I added comments that I hope clarify things. Let me know.
 
Thanks for the update.. I'm still getting a crash: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<SpontiStoryboard.ChatViewController: 0x7fb6b102fe00>) has no segue with identifier 'chatToInvite'' <- this happens after the menu dismisses itself. For reference chat = origin and invite = destination.
I did set up that chatToInvite segue from the chat (origin) to invite (destination), and put your suggested code in the IBAction of the invite button being pressed in the menu.
 
Are you sure you named your segue in the storyboard? Select the segue in the storyboard, go to Attributes inspector, make sure Identifier is set to "chatToInvite".
 
I did, double checked that and made sure spelling was correct also: imgur.com/a/zF051
 
9:21 PM
Hmmm... Well the error is very specifically saying it can't find the segue. Are you sure it is wired up from the ChatViewController to the Invite? How are you creating ChatViewController to begin with?
 
Yeah, I definitely drew the segue from Chat to Invite. And I'm not sure what you mean by how did I create the controller
 
Is your Chat the initial view controller, or did you instantiate it using UIStoryboard.instantiateViewController(withIdentifier:) or otherwise?
You might also trying cleaning your project with Cmd+Shift+K and restarting Xcode. Something isn't right with the segue setup, and it might not be anything you did.
 
I don't mention the chat controller in the code at all really, other than when I segue to it from the previous controller in the app with let chatVc = segue.destination as! ChatViewController in prepareForSegue. And it's not the initial view controller - the app launches on a list of chat rooms (assuming you're already logged in, if not if launches on the login screen). Then when you select a room, it goes to the chat.
Hey Mike, thanks for helping out this is really strange
 
Yeah, it is. Do you have a picture of your storyboard?
 
Sure, one sec
Let me know if you need to see other parts expanded: imgur.com/a/ZX1mn
It looks messy but for now everything works pretty well navigation-wise. If I use an unwind like another answerer suggested, I can successfully go from the invite VC back to Chat, but it stops on the menu momentarily which doesn't look good
 
9:27 PM
Not messy at all. But it still looks like you have a segue from Menu to Invite VIP.
 
Yes, that's the segue to open Invite, before unwinding back to Chat (while stopping briefly on Menu which is suboptimal). I just comment out that segue when I use your method - is the fact that it's there at all causing issues?
So I just removed that segue entirely and got the same crash
 
OK, well that wasn't it. :) But you aren't going to want that segue anyway, if we can get this approach to work.
Can you make sure you don't have a trailing space after chatToInvite in the storyboard?
 
This is my exact code in the menu controller for when I tap the "Invite" button:
@IBAction func invitePressed(_ sender: Any) {
    weak var pvc = self.presentingViewController
    self.dismiss(animated: true) {
        pvc?.performSegue(withIdentifier: "chatToInvite", sender: nil)
    }
}
Ok, I'll check on that
 
Yep, but I mean in the storyboard
 
negative on the trailing space
 
9:32 PM
Odd. Did you try Cmd+Shift+K to clean your project and then restart Xcode?
 
I did, unfortunately the issue persists! Very strange indeed.
 
Maybe try deleting the segue, re-adding it with a different name.
Feels like storyboard is a little confused. There is nothing wrong with your code that I can see
 
Just tried it - deleted the segue, reconnected it as "chatInvite", changed the segue name in the code, and got the same error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<UINavigationController: 0x7fef44837400>) has no segue with identifier 'chatInvite''
Programming is so much fun sometimes
Could it be the navigation controller is the problem somehow? I'm fairly new so I wouldn't know whats going on, but the Invite VC is not in the navigation controller. And the chat controller is (sort of), is the JSQMessagesViewController
 
Did you notice this time it refers to UINavigationController, last time ChatViewController?
 
Because the error doesn't say ChatViewController has no segue named that, it's UINavigationController
Yup! That might be part of it
Maybe draw the segue from the nav controller to the invite controller?
Ok, yup, that was it
Sorry, that was a big newbie mistake. If you want to suggest this solution in the answer I'd be glad to accept it
 
9:42 PM
Wait, did it work?
 
Haha yes, that was it! I just drew the segue from the navigation controller to the invite controller instead of from chat -> invite
 
Aha, good find! OK, so do you get the behavior you want, as far as the Menu not showing up after dismissing Invite? You go back to Chat?
 
Exactly, yeah, it's working well. Tapping the invite button in the menu dismisses the menu, and for a split second I see the chat before the invite controller comes up. Then dismissing the invite controller goes back to the chat
 
Cool! I will update my answer with a note about wiring the segue from the nav controller. If you'd like to accept that, I'd appreciate it. Good luck on the rest of your project!
 
Thanks Mike, I appreciate your time and will definitely accept your answer! Have a good weekend.
 
9:48 PM
You too. Take care
 

last day (14 days later) »