我有我有两种方法在不同的类。一个是类方法,另一个是实例方法。我从实例方法调用类方法。当实例方法完成时,会给运行时错误“EXC_BAD_ACCESS”。NSArray运行时数组
#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
代码有什么问题?同时也是应用崩溃的这行代码 应用程序崩溃,如果我加入这一行
NSArray *bgColor = [[NSArray alloc] initWithArray:[xmlObject fetchImmediateChildrenValues:[del.navigationbarStyle objectForKey:@"backgroundcolor"]]];
如果我删除应用程序运行速度流畅。
'xmlObject'从哪里来? – d11wtq 2010-06-04 08:51:10
此外,'textmeAppDelegate'是一个有效的类型?它看起来更像是一个实例变量的名称,而不是一个类型,但是您试图将它用作类型。 – d11wtq 2010-06-04 08:53:03
xmlObject是在文件开始处导入的类。和textmeAppDelegate是一个有效的类型,因为它是我在我的应用程序的不同部分调用委托。 – 2010-06-04 09:49:37