我有我有兩種方法在不同的類。一個是類方法,另一個是實例方法。我從實例方法調用類方法。當實例方法完成時,會給運行時錯誤「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