How to handle two segues going to the same view controller?
I have an iPhone app I'm currently building in XCode 4.3 with Storyboard. I have a "root" view controller with two (2) seques to a view controller containing a UIWebView. I want to be able to identify the segue (have already set unique identifiers for both segues) so I can "push" the correct content to the UIWebView, based on which segue was activated in the "root" view controller.
I think I have to use "prepareForSegue" method, but don't know where it would go. Where can I find out how to deal with two segues going to the same view controller? (I have google'd it and found nothing appropriate to my situation).
Here is the code that I'm using:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"helpSegue"]) {
NSLog(@"helpSegue");
}
else if ([segue.identifier isEqualToString:@"reportSegue"]) {
NSLog(@"reportSegue");
}
}
You won't call -prepareForSegue:sender:
, you'll implement it in your view controller. In it's override of that method, you can check the segue's identifier
property (the segue is passed in as a parameter):
if ([segue.identifier isEqualToString:@"Segue Numero Uno"]) {
// do something here
}
That lets you take some sort of action depending on which segue is causing the transition. You can set the identifier for each segue in the storyboard editor.
Update: Based on the code you provided in your comment (which I've added to your question), you've got the right idea now. At this point, it's just a matter of good old fashioned debugging. Some things to check:
Is the view controller in your storyboard (ie the one that the segues in question lead to) set up as an instance of the class which implements this -prepareForSegue:sender:
? Check the controller's type in the storyboard.
Do the strings you use in your code exactly match the identifiers that you set for your segues in the storyboard? Capitalization, spelling, punctuation, and white space all count.
Is your -prepareForSegue:sender:
method being called? Put a breakpoint there and debug. If it is being called, what is the identifier for the segue
that's passed in? If it's not being called, the view controller in the storyboard doesn't have the right class.
上一篇: 使用websocket + node.js与具有xmpp的本地客户端聊天服务器
下一篇: 如何处理两个赛段去相同的视图控制器?