J'ai deux méthodes dans deux classes. L'une est la méthode de classe et l'autre est la méthode de l'instance. J'appelle la méthode de classe de la méthode d'instance. Lorsque la méthode d'instance se termine, l'erreur d'exécution "EXC_BAD_ACCESS" est générée.Numéro de désallocation NSMUtableDictionary
#import "xmlObject.h"
#import "textmeAppDelegate.h"
@implementation Class1
- (void)method1 {
textmeAppDelegate *del = (textmeAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *bgColor = [[NSArray alloc] initWithArray:[xmlObject fetchImmediateChildrenValues:[del.navigationbarStyle objectForKey:@"backgroundcolor"]]];
UIColor *color = [UIColor colorWithRed:[[bgColor objectAtIndex:3] floatValue] green:[[bgColor objectAtIndex:2] floatValue] blue:[[bgColor objectAtIndex:1] floatValue] alpha:[[bgColor objectAtIndex:0] floatValue]];
CGContextSetFillColor(context, CGColorGetComponents([color CGColor]));
CGContextFillRect(context, rect);
[bgColor release];
}
@end
@implementation xmlObject
+ (NSArray *) fetchImmediateChildrenValues:(NSMutableDictionary *) node {
NSMutableDictionary *tmp = [[node objectForKey:@"children"] retain];
NSArray *keys = [[NSArray alloc] initWithArray:[tmp allKeys]];
keys = [keys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSMutableArray *pushArr = [[[NSMutableArray alloc] init] autorelease];
NSString *val = [[NSString alloc] init];
for(NSString *str in keys) {
val = (NSString *)[[tmp objectForKey:str] objectForKey:@"innertext"];
[pushArr addObject:val];
}
[val release];
[keys release];
return [NSArray arrayWithArray:pushArr];
}
@end
Quel est le problème avec le code? Aussi l'application se bloque pour cette ligne de code l'application se bloque si j'insérez la ligne
NSArray *bgColor = [[NSArray alloc] initWithArray:[xmlObject fetchImmediateChildrenValues:[del.navigationbarStyle objectForKey:@"backgroundcolor"]]];
Si je le supprimer l'application fonctionne bien.
Merci qui l'a fait. maintenant est aussi en me donnant malloc: *** erreur pour l'objet 0x43181e0: double gratuit sur le lancement de l'application. Des idées pourquoi cela arrive? –