Does Segue Exist?
-
28-05-2021 - |
Pergunta
Does anyone know if there is a way to determine whether a segue with a particular name exists? Or alternatively, if there's a way to get a list of all the named segues that iOS knows about
Solução
no, your method only detect when a particular segue is fired. but you can't test if a segue exist, by another way than try to call it. it seems that the only way is to use @try @catch :
@try {
[self performSegueWithIdentifier:@"Replace_Connected" sender:self];
}
@catch (NSException *exception) {
NSLog(@"%@ no segue with identifier 'Replace_Connected' : %@", [self description], exception);
}
@finally { }
Outras dicas
I suggest you file a bug. The storyboard clearly knows all the segues emanating from a given scene:
<viewController id="2" customClass="ViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="3">
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
<connections>
<segue destination="t3N-Fe-gqq" kind="modal" identifier="myCoolSegue" id="AYQ-C4-4vO"/>
</connections>
</viewController>
So why isn't a view controller instance allowed to ask for that information? Also, a view controller has a storyboard
property so why doesn't it have a segues
property? I think you have legitimate grounds for a feature request.
You can check to see if a Segue exists by using the prepareForSegue
method :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure we are dealing with the proper Segue
if ([segue.identifier isEqualToString:@"MySegueID"]) {
// Exists, do something
}
}
If there is a way to list all the Segues, I don't know about it and I haven't seen it in the docs.