Ich habe ein Array, das ich durchsuche und nach einem bestimmten Flag suche. Wenn der Flag-Wert Null ist, rufe ich eine Methode auf, die ein Aufrufobjekt erzeugt und das Ergebnis des Aufrufs zurückgibt.NSInvocation gibt Wert zurück, aber App stürzt ab mit EXC_BAD_ACCESS
My Codestruktur ist als
for(NSString *key in [taxiPlanes allKeys])
{
Plane *currentPlane = [taxiPlanes objectForKey:key];
if(currentPlane.currentAction == nil)
{
NSString *selector = [[currentPlane planeTakeoffSequence] firstObject];
currentPlane.currentAction = selector;
// Calling for NSInvocation in [self ...]
NSArray *action = [NSArray arrayWithArray:[self operationFromTakeoffAction:currentPlane.currentAction AtPoint:currentPlane.position]];
NSLog(@"%@",action);
}
}
Methode, die NSInvocation
-(NSArray *) operationFromTakeoffAction:(NSString *) action AtPoint:(CGPoint) flightPoint
{
NSMethodSignature *methodSignature = [FlightOperations instanceMethodSignatureForSelector:NSSelectorFromString(action)];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
[invocation setTarget:fOps];
[invocation setSelector:NSSelectorFromString(action)];
[invocation setArgument:&flightPoint atIndex:2];
NSArray *resultSet = [NSArray alloc]init];
[invocation invoke];
[invocation getReturnValue:&resultSet];
return resultSet;
}
In der for-Schleife erzeugt folgt, ohne den Methodenaufruf für NSInvocation ([self ....]), der Die Schleife wird einfach ausgeführt und stürzt nicht ab. Aber wenn ich die Methode zum Aufrufen von NSInvocation einführe, kann ich sehen, dass NSLog in für den Ausdruck das erwartete NSArray-Ergebnis druckt, aber es stürzt mit der Fehlermeldung EXC_BAD_ACCESS ab.
Ich kann nicht herausfinden, warum es fehlschlägt, obwohl NSInvocation ordnungsgemäßes Ergebnis zurückgibt. Ohne NSInvocation wird for-Schleife nicht abgestürzt.
Alle Vorschläge wären hilfreich.
Danke
haben Sie weitere Informationen haben auf zu diskutieren, sagte sein der Absturzgrund von der Konsole oder vom Debugger? – Volker
Die Konsole zeigt keine weiteren Informationen an. Alles, was ich bekomme, ist Thread 1: EXC_BAD_ACCESS (code = EXC_i386_GPFLT) – slysid
Setup NSZombieEnabled. Es gibt Ihnen mehr Informationen. Siehe http://stackoverflow.com/questions/2190227/how-do-i-set-up-nszombeenenabled-in-xcode-4 – asgoth