Некоторый код вместо длинного объяснения.Проблема:
При вызове из viewDidLoad
серверный вызов вызывает методы делегатов (connectionDidFinishLoading и т. Д.).Но при вызове из XMLFileFullParsed
запрос запускается на сервер, но те же методы не запускаются.
Если я вызываю [self loadXMLDatas]
вместо потоков, то оба вызова сервера работают нормально.
Почему?
Я начинаю здесь:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(foundaTag:) name:@"foundaTag" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(XMLFileFullParsed:) name:@"XMLFileFullParsed" object:nil];
self.server = [[ServerCommManager alloc] initWithServer:@"http://someserver/"];
[self.server sendQuestionWithCallIdentifier:@"IDENTIFIER" onPage:@"testpage.php" withParams:nil sendAnswerToObject:self]; // -- This one works
[NSThread detachNewThreadSelector:@selector(loadXMLDatas) toTarget:self withObject:nil];
}
- (void) loadXMLDatas {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
Do things, create a XMLparser, start to parse.
[pool release];
}
- (void) XMLFileFullParsed:(NSNotification*)notification {
[self.server sendQuestionWithCallIdentifier:@"IDENTIFIER" onPage:@"testpage.php" withParams:nil sendAnswerToObject:self]; // -- This one doesn't work
}
XMLParser.m
- (void) doYourJob {
[self doTheJob];
[[NSNotificationCenter defaultCenter] postNotificationName:@"XMLFileFullParsed" object:nil userInfo:nil];
}
- (void) doTheJob:(XMLTag*)tag {
if ([tag.name isEqualToString:@"searchedtag"]) {
theData = extract some datas
[[NSNotificationCenter defaultCenter] postNotificationName:@"foundaTag" object:self userInfo:[NSDictionary dictionaryWithObject:theData forKey:@"data"]];
return;
}
for (XMLTag* aTag in tag.childtags) {
[self doTheJob:aTag];
}
}
Глубоко внутри сервера comm.m
- (void) executeRequest {
some init
self.connection = [NSURLConnection connectionWithRequest:urlRequest delegate:self];
}
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response {
}
- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data
{
}
- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error
{
}
- (void)connectionDidFinishLoading:(NSURLConnection*)connection
{
}