我终于在我的应用程序中没有泄漏,但我仍然设法让我的应用程序不时崩溃......这真的很罕见,但它让我生气;)
这是我得到的:
2010-05-11 19:36:29.487 Infonul[2457:20b] *** -[NSCFString _setParserError:]: unrecognized selector sent to instance 0x3cddb80
[Session started at 2010-05-11 19:36:29 +0200.]
2010-05-11 19:36:29.487 Infonul[2457:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFString _setParserError:]: unrecognized selector sent to instance 0x3cddb80'
2010-05-11 19:36:29.488 Infonul[2457:20b] Stack: (
9479259,
2423766587,
9861179,
9430646,
9283266,
4372334,
56536,
4191652,
4191507,
12699064,
12697112,
12697826,
12697826,
12700310,
12359637,
9263329,
9260104,
825261,
825458,
23633923
)
这里似乎失败了:
// after having downloaded the file to parse
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
CommentsParserDelegate *commentsParserDelegate = [[CommentsParserDelegate alloc] initWithController:self];
//commentsParserDelegate.commentController = self;
commentsParser = [[NSXMLParser alloc] initWithData:self.activeDownload];
[commentsParser setDelegate:commentsParserDelegate];
[commentsParser parse]; //last function called before crash
}
不知道为什么应用程序崩溃,我不明白调试器试图告诉我的是什么:D
希望有人有所了解;)
谢谢。
高堤耶。
答案 0 :(得分:2)
调试器试图告诉您(或者,更有可能的是,框架)正在尝试在类NSString的对象上调用名为_setParserError的方法。在NSString中没有这样的方法。
答案 1 :(得分:0)
以下是“CommentsParserDelegate.m”的代码
//
// CommentsParserDelegate.m
// Infonul
//
// Created by eef16514f684e5d on 26/03/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "CommentsParserDelegate.h"
@implementation CommentsParserDelegate
@synthesize currentElement;
//@synthesize commentController;
- (id)initWithController:(CommentsViewController *)comment {
if (self = [super init]) {
commentController = comment;
months = [[NSArray alloc] initWithObjects:@"Jan.",@"Fév.",@"Mars",@"Avril",@"Mai",@"Juin",@"Juil.",@"Août",@"Sept.",@"Oct.",@"Nov.",@"Déc.",nil];
}
return self;
}
- (void)parserDidStartDocument:(NSXMLParser *)parser {
comments = [[NSMutableArray alloc] init];
//currentElement = [[NSString alloc] init];
currentContent = [[NSMutableString alloc] init];
currentAuthor = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
self.currentElement = elementName;
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"item"]) {
// save values to an item, then store that item into the array...
CommentRecord *comment = [[CommentRecord alloc] init];
[comment setAuthor:[[[NSString alloc] initWithString:[currentAuthor stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]] autorelease]];
[currentAuthor setString:@""];
[comment setContent:[[[NSString alloc] initWithString:[currentContent stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]] autorelease]];
[currentContent setString:@""];
NSString *tempDate = [[[NSString alloc] initWithString:[currentDate stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]] autorelease];
NSMutableString *tempString = [[NSMutableString alloc] initWithString:[tempDate substringToIndex:2]];
NSString *month = [[tempDate substringFromIndex:3] substringToIndex:2];
[tempString appendString:@" "];
[tempString appendString:[months objectAtIndex:[month intValue]-1]];
[tempString appendString:@" "];
[tempString appendString:[[tempDate substringFromIndex:6] substringToIndex:4]];
[tempString appendString:@" à "];
[tempString appendString:[[tempDate substringFromIndex:11] substringToIndex:8]];
[comment setDate:[[[NSString alloc] initWithString:tempString] autorelease]];
[tempString release];
[currentDate setString:@""];
[comments addObject:comment];
[comment release];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if (([currentElement isEqualToString:@"author"])) {
[currentAuthor appendString:[self flattenTEXT:string]];
}
else if (([currentElement isEqualToString:@"content"])) {
[currentContent appendString:string];
}
else if (([currentElement isEqualToString:@"date"])) {
[currentDate appendString:string];
}
}
- (NSString *)flattenTEXT:(NSString *)link
{
//link = [link stringByReplacingOccurrencesOfString:@" " withString:@""];
link = [link stringByReplacingOccurrencesOfString:@"\n" withString:@""];
link = [link stringByReplacingOccurrencesOfString:@"\t" withString:@""];
link = [link stringByReplacingOccurrencesOfString:@"\r" withString:@""];
return link;
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[currentDate release];
[currentContent release];
[currentAuthor release];
[self.currentElement release];
[commentController displayData:comments];
}
- (void)dealloc {
[comments release];
[months release];
[super dealloc];
}
/*
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
NSLog(parseError.description);
}
*/
@end
那会有帮助吗?
答案 2 :(得分:0)
日志是否总是说选择器正在发送到NSString对象,或者对象类型是否有所不同?如果它变化,通常是内存管理问题的标志。