【发布时间】:2012-02-24 09:31:06
【问题描述】:
我是 Objective-C 的新手
我已将一个Array 集成到另一个Array 中,它可以工作
我的问题:我经常使用Row *row = [[Row alloc] init];,但我认为经常使用此代码是不对的。请看我的代码,你会发现 3 倍的代码。
我的 XMLPARSER.h
@interface XMLParser : NSObject <NSXMLParserDelegate> {
// veränderlicher String
NSMutableString *currentString;
BOOL storingCharacters;
//unveränderliche Strings
NSString *user;
NSString *score;
NSString *idValue;
NSString *responseCode;
int index;
//Klasse von NSArray, objekte können hinzugefügt und verändert werden, keine feste Anzahl von Elementen
NSMutableArray *rows;
}
@property (nonatomic, retain) NSMutableString *currentString;
@property (nonatomic, retain) NSString *user;
@property (nonatomic, retain) NSString *score;
@property (nonatomic, retain) NSString *idValue;
@property (nonatomic, retain) NSString *responseCode;
@property (nonatomic) BOOL storingCharacters;
@property (nonatomic, retain) NSMutableArray *rows;
- (void)parseXMLFile:(NSString *)pathToFile;
- (void)print;
@end
@interface Row: NSObject{
NSString *user;
NSString *score;
NSMutableArray *ids;
int index;
}
@property (nonatomic, retain) NSString *user;
@property (nonatomic, retain) NSString *score;
@property (nonatomic, retain) NSMutableArray *ids;
@property (nonatomic) int index;
@end
我的 XMLPArser.c
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:kName_response]) {
}else if ([elementName isEqualToString:kName_responseCode]) {
self.responseCode=[[NSString alloc] initWithString: currentString];
}else if ([elementName isEqualToString:kName_rows]) {
}else if ([elementName isEqualToString:kName_row]) {
Row *row = [[Row alloc] init];
row.user=self.user;
row.score=self.score;
[self.rows insertObject:row atIndex:index];
index=index+1;
[row release];
}else if ([elementName isEqualToString:kName_user]) {
self.user=[[NSString alloc] initWithString: currentString];
}else if ([elementName isEqualToString:kName_score]) {
self.score=[[NSString alloc] initWithString: currentString];
}
else if ([elementName isEqualToString:kName_extra]) {
Row *row = [[Row alloc] init];
NSLog(@"indexwert:%@",row.index);
row.index = 0;
[row release];
}
else if ([elementName isEqualToString:kName_ids]) {
self.idValue=[[NSString alloc] initWithString: currentString];
Row *row = [[Row alloc] init];
row.ids = [[NSMutableArray alloc] init];
[row.ids insertObject:idValue atIndex:row.index];
NSLog(@"The number!!!! %@ in %@ ",idValue, [row.ids objectAtIndex:row.index]); //it works
row.index = row.index+1;
// NSLog(@"hallo %@",idValue); //it works
[row.ids release];
[row release];
}
storingCharacters = NO;
}
我的代码对吗?
【问题讨论】:
-
我不知道问题是什么(除了奇怪的代码格式!),请进一步详细说明。
标签: objective-c arrays xcode xml-parsing