@H_419_8@
@H_419_8@
- (voID)getAllNewDatabases { [self performSelectorOnMainThread:@selector(getNewDatabase:) withObject:@"file1" waitUntilDone:YES]; [self performSelectorOnMainThread:@selector(getNewDatabase:) withObject:@"file2" waitUntilDone:YES];}- (BOol)getNewDatabase:(Nsstring *)dbname{ NSautoreleasePool *pool = [[NSautoreleasePool alloc] init]; NSMutableString *APIString = [[NSMutableString alloc] initWithString:kAPIHost]; [APIString appendFormat:@"/%@.pList",dbname]; NSURLRequest *myRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:APIString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; NSURLConnection *myConnection = [[NSURLConnection alloc] initWithRequest:myRequest delegate:self]; [APIString release]; if( myConnection ) { //omitted for clarity here } [pool release];}//NSURLConnection delegate methods here ...解决方法 我发现了一些有趣的NSURLConnection和NSThread – 只要执行你从中调用的方法,线程就会生存.
@H_419_8@
在上面的情况下,只要getNewDatabase:(Nsstring *)dbname完成,线程就会生效,因此在它们实际有时间做任何事情之前,它会删除它的任何委托方法.@H_419_8@
我找到了this网站,提供了更好的解释和问题的解决方案@H_419_8@
我稍微调整了一下,如果它没有在给定的时间范围内完成,我可以有一个自定义的时间(当有人在接入点之间走动时很方便)@H_419_8@
@H_419_8@
start = [NSDate dateWithTimeIntervalSinceNow:3]; while(!isFinished && [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]){ if([start compare:[NSDate date]] == NSOrderedAscending){ isFinished = YES; }}总结
以上是内存溢出为你收集整理的NSURLConnection委托和线程 – iPhone全部内容,希望文章能够帮你解决NSURLConnection委托和线程 – iPhone所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)