Skip initial view controller if it doesn't exist

This commit is contained in:
root 2025-05-12 19:04:11 -04:00
parent 43feefce68
commit 7850f8e61b
2 changed files with 77 additions and 58 deletions

View file

@ -612,68 +612,82 @@
if ([docNodes count] > 0) if ([docNodes count] > 0)
{ {
NSXMLElement *docNode = [docNodes objectAtIndex: 0]; NSXMLElement *docNode = [docNodes objectAtIndex: 0];
NSArray *array = [docNode nodesForXPath: @"//scene" error: NULL];
NSArray *firstResponderIdNodes = [docNode nodesForXPath: @"//objects/customObject[@sceneMemberID =\"firstResponder\"]/@id"
error: NULL];
NSString *firstResponderId = @"-1";
if([firstResponderIdNodes count] > 0) if (docNode != nil)
{ {
firstResponderId = [[firstResponderIdNodes objectAtIndex: 0] stringValue]; NSArray *array = [docNode nodesForXPath: @"//scene" error: NULL];
} NSArray *firstResponderIdNodes = [docNode nodesForXPath: @"//objects/customObject[@sceneMemberID =\"firstResponder\"]/@id"
error: NULL];
NSString *firstResponderId = @"-1";
NSXMLNode *initialViewControllerNode = [docNode attributeForName: @"initialViewController"];
// Set initial view controller... if([firstResponderIdNodes count] > 0)
ASSIGN(_initialViewControllerId, [[docNode attributeForName: @"initialViewController"] stringValue]); {
FOR_IN(NSXMLElement*, e, array) firstResponderId = [[firstResponderIdNodes objectAtIndex: 0] stringValue];
{ }
NSXMLElement *doc = [[NSXMLElement alloc] initWithName: @"document"];
NSArray *children = [e children];
NSXMLDocument *document = nil;
NSString *sceneId = [[e attributeForName: @"sceneID"] stringValue];
NSString *controllerId = nil;
// Move children...
FOR_IN(NSXMLElement*, child, children)
{
if ([[child name] isEqualToString: @"point"] == YES)
continue; // go on if it's a point element, we don't use that in the app...
NSArray *subnodes = [child nodesForXPath: @"//application" error: NULL]; // Set initial view controller...
NSXMLNode *appNode = [subnodes objectAtIndex: 0]; if (initialViewControllerNode != nil)
[self processChild: child {
withDoc: doc ASSIGN(_initialViewControllerId, [[docNode attributeForName: @"initialViewController"] stringValue]);
withAppNode: appNode }
sceneId: sceneId
firstResponderId: firstResponderId];
// fix other custom objects FOR_IN(NSXMLElement*, e, array)
document = [[NSXMLDocument alloc] initWithRootElement: doc]; {
controllerId = [self controllerIdWithDocument: document]; NSXMLElement *doc = [[NSXMLElement alloc] initWithName: @"document"];
controllerId = (controllerId != nil) ? controllerId : APPLICATION; NSArray *children = [e children];
RELEASE(doc); NSXMLDocument *document = nil;
NSString *sceneId = [[e attributeForName: @"sceneID"] stringValue];
NSString *controllerId = nil;
// Move children...
FOR_IN(NSXMLElement*, child, children)
{
if ([[child name] isEqualToString: @"point"] == YES)
continue; // go on if it's a point element, we don't use that in the app...
// Create document... NSArray *subnodes = [child nodesForXPath: @"//application" error: NULL];
[_scenesMap setObject: document NSXMLNode *appNode = [subnodes objectAtIndex: 0];
forKey: sceneId]; [self processChild: child
withDoc: doc
withAppNode: appNode
sceneId: sceneId
firstResponderId: firstResponderId];
// Map controllerId's to scenes... // fix other custom objects
if (controllerId != nil) document = [[NSXMLDocument alloc] initWithRootElement: doc];
{ controllerId = [self controllerIdWithDocument: document];
[_controllerMap setObject: sceneId controllerId = (controllerId != nil) ? controllerId : APPLICATION;
forKey: controllerId]; RELEASE(doc);
[self processSegues: document // Create document...
forControllerId: controllerId]; [_scenesMap setObject: document
} forKey: sceneId];
RELEASE(document);
} // Map controllerId's to scenes...
END_FOR_IN(children); if (controllerId != nil)
} {
END_FOR_IN(array); [_controllerMap setObject: sceneId
forKey: controllerId];
[self processSegues: document
forControllerId: controllerId];
}
RELEASE(document);
}
END_FOR_IN(children);
}
END_FOR_IN(array);
}
else
{
[NSException raise: NSInternalInconsistencyException
format: @"No document element found in storyboard file"];
}
} }
else else
{ {
[NSException raise: NSInternalInconsistencyException [NSException raise: NSInternalInconsistencyException
format: @"No document element found in storyboard file"]; format: @"Document node returned nil"];
} }
} }

View file

@ -164,8 +164,13 @@ static NSStoryboard *__mainStoryboard = nil;
- (id) instantiateControllerWithIdentifier: (NSStoryboardSceneIdentifier)identifier - (id) instantiateControllerWithIdentifier: (NSStoryboardSceneIdentifier)identifier
{ {
return [self instantiateControllerWithIdentifier: identifier if (identifier != nil)
creator: nil]; {
return [self instantiateControllerWithIdentifier: identifier
creator: nil];
}
return nil;
} }
- (id) instantiateControllerWithIdentifier: (NSStoryboardSceneIdentifier)identifier - (id) instantiateControllerWithIdentifier: (NSStoryboardSceneIdentifier)identifier