Reputation: 1335
I'm dealing with a segue problem and it's getting ridiculous.
I'm performing it like how I always do in a view controller named LoginViewController
:
- (void)loginSuccessfullyAccomplished
{
[self performSegueWithIdentifier:@"switchToHome" sender:self];
}
The method above is called from another Class, where some other signing in actions is performed asynchronously, and when it is done, it calls this method from LoginViewController.m
:
// Some Code
.
.
.
.
case VIDYO_CLIENT_OUT_EVENT_SIGNED_IN:
{
/*** Notifying upper layer ( Login View Controller ) from signing in ***/
UIStoryboard *storyboard;
if ( IDIOM == IPAD )
{
storyboard = [UIStoryboard storyboardWithName:@"MasterStoryboard-iPad" bundle:nil];
}
else if ( IDIOM == IPHONE )
{
storyboard = [UIStoryboard storyboardWithName:@"MasterStoryboard-iPhone" bundle:nil];
}
UINavigationController *nav = [storyboard instantiateInitialViewController] ;
dispatch_async(dispatch_get_main_queue(), ^{
[nav.viewControllers[0] loginSuccessfullyAccomplished];
});
break;
}
.
.
.
.
//Rest of the code
Now, Here's the problem :
loginSuccessfullyAccomplished
is being called successfully (Used breakpoints to make sure of that), But I don't see the second view controller to appear on the screen.
I get no error and no exceptions when performSegue
is executed, that means I'm not making any mistake regarding the segue identifier or first view controller from which the segue is being performed.
I'm also sure that I'm using a push segue and I HAVE embedded my view controllers in a navigation controller.
Just to make sure I'm not doing anything wrong with the segue itself, I implemented prepareForSegue
method and it IS BEING called. I also have checked that it is pointing to correct destination :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ( [segue.destinationViewController isKindOfClass:[UserHomeViewController class]] )
{
NSLog(@"YES");
}
}
The second view controller IS NOT visually similar to first view controller, so I definitely will notice if it changes.
I have no idea what is going wrong. Any suggestions is really appreciated.
Thanks.
P.S: I know there're dozens of " performSegueWithIdentifier
not being called " questions but none of them helped my case!!!
Upvotes: 0
Views: 230
Reputation: 62676
The method is being called successfully, but on which instance? The code in the IDIOM == IPHONE
block is highly suspect. It's calling loginSuccessfullyAccomplished
on an brand new instance, one that hasn't been presented, so it's not a surprise that we wouldn't see any change in the UI.
What I think you need in the object where the login logic is running is a reference to the instance of the LoginViewController
that's actually been presented. You can do that by making it a delegate. Maybe better, don't bother with pointers.... have the login logic post an NSNotification
that login has finished, and have the LoginViewController
observe that and dismiss itself.
Upvotes: 2