问题
I have two View Controllers, V1 and V2. V1 presents V2 with a modal segue in storyboard. I then have an unwind segue that dismisses V2 to go to V1. The Done action belowed is then called. It prints out the correct NSLog's, however the [self performSegueWithIdentifier:@"viewmessagessegue" sender:self]
does not get initiated. I use that same line of code when a button in V1 is pressed, and it works correctly in that scenario. I'm confused as to why it's not being called...
- (IBAction)done:(UIStoryboardSegue *)segue {
SendToViewController *cc = [segue sourceViewController];
_users = cc.recipients;
NSLog(@"users: %@",_users"); // has the correct data
[self performSegueWithIdentifier:@"viewmessagessegue" sender:self];
NSLog(@"perform segue...:"); // this gets printed
}
回答1:
I'm not positive of the answer on this one, but I think when "done:" is executed, it's really not executed in that class (meaning the class of the previous screen). It's either executing in an in-between place or in the calling class (meaning the class of the screen you are trying to unwind from). If this is true, it will try to execute prepareForSegue: from the unwind side rather than from V1 side and since there probably isn't a segue.identifier, it just continues on as if it didn't find one....Please don't take this as gospel...I'm guessing here, but I may not be too far off the mark. You could probably put a NSLog in the V2 prepareForSegue: to check it.
来源:https://stackoverflow.com/questions/21503886/performing-programmatic-segue-after-unwind