- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在开发一个 iphone 应用程序,我在其中提取 RSS 提要然后解析它们。我的代码如下所示:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"in view did appear");
if ([stories count] == 0) {
NSString * path = @"http://www.shire.com/shireplc/rss.jsp";
//[self parseXMLFileAtURL:path];
//[self performSelectorInBackground:@selector(parseXMLFileAtURL:) withObject:path];
NSLog(@"internet is %d",[self checkInternet]);
if([self checkInternet]==1)
[NSThread detachNewThreadSelector:@selector(parseXMLFileAtURL:)
toTarget:self withObject:path];
}
}
- (void)parseXMLFileAtURL:(NSString *)URL
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
stories = [[NSMutableArray alloc] init];
//you must then convert the path to a proper NSURL or it won't work
NSURL *xmlURL = [NSURL URLWithString:URL];
// here, for some reason you have to use NSClassFromString when trying to alloc NSXMLParser, otherwise you will get an object not found error
// this may be necessary only for the toolchain
rssParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
// Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
[rssParser setDelegate:self];
// Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
[rssParser setShouldProcessNamespaces:NO];
[rssParser setShouldReportNamespacePrefixes:NO];
[rssParser setShouldResolveExternalEntities:NO];
[rssParser parse];
[pool release];
}
谁能告诉我哪里出错了?我的日志如下: 日志:[切换到线程 12803] [切换到线程 12035] 2011-05-10 11:31:30.932 年度报告 [454:490b] 找到文件并开始解析 [切换到线程 14339] 2011-05-10 11:32:04.742 年度报告 [454:640b] 找到文件并开始解析 [切换到线程 13827] [切换到线程 13827] 程序收到信号:“EXC_BAD_ACCESS”。
gdb stack trace at 'putpkt: write failed':
0 gdb-arm-apple-darwin 0x0019026b remote_backtrace_self + 54
最佳答案
我不确定,但我猜该方法的参数会在某个时候被释放。您能否确保方法 parseXMLFileAtURL
关于iphone - detachNewThreadSelector 使应用程序随机崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5938569/
我正在开发一个 iphone 应用程序,我在其中提取 RSS 提要然后解析它们。我的代码如下所示: - (void)viewDidAppear:(BOOL)animated { [super
我知道 分离新线程选择器:toTarget:withObject 可以有一个 (id)anArgument。我已经搜索过它可以用于 NSString。 但是,当我传递一个整数或 size_t 时,它崩
我正在开发一个由其他人设计的应用程序。该应用程序充满了这样的调用: [NSThread detachNewThreadSelector:@selector(loadPhotoImage) toTarg
我正在努力每 60 秒在后台执行一些任务。后台任务是服务器请求从网站下载文件。当请求完成并且我正在将数据保存到 sqlite 时,主线程/UI 似乎正在锁定。 NSAutoreleasePool *p
我一直在许多应用程序中使用 -performSelectorInBackground,有点忘记了 -detachNewThreadSelector。现在我想知道两者之间有什么区别。它们是否几乎可以互换
少数客户在我的 OS X 应用程序中遇到了以下挂起日志签名的挂起: 26 ??? [0x7fff93e87fc9] 26 ??? [0x7fff93e8372a] 26 ??? [0x7fff93
我正在使用 detachNewThreadSelector 创建一个新线程 ref使用 toTarget self. 该线程的目的是轮询运动并根据需要加载图像 - 它循环并仅在主线程中的原子 bool
我需要执行异步函数执行,因为它阻塞了主线程,因此 UI 不可用。 看了stackoverflow的题目,知道了异步函数的三种方式。 一个例子: [NSThread detachNewThreadSel
该应用程序在 iOS 7 中正常运行,但当我疯狂地切换到 iOS 8 时,该应用程序无法按预期方式运行。在 Debug模式下,调用应用程序中的 NSThread detachNewThreadSele
我正在使用 block 在异步调用中下载图像。我知道如何以这种方式使用 block [self getimage:url block:^(UIImage *img) { passblock
在 NSThread 文档中,我遇到了方法 detachNewThreadSelector:toTarget:withObject:。该方法与使用 initWithTarget:selector:ob
您好,我正在使用 [NSThread detachNewThreadSelector:toTarget:withObject:] 并且我遇到了很多内存泄漏,因为我没有为分离线程设置自动释放池。我只是想
我对 Objective C 语法还很陌生,所以我可能会让这个变得过于复杂,但我似乎无法弄清楚如何将 NSTimeInterval 传递给线程。 我想启动一个休眠 x 秒的线程,从主线程发送参数如下:
它们似乎执行相当相似的任务:启动一个新线程来快速轻松地执行该选择器。但有什么区别吗?也许与内存管理有关? 最佳答案 两者是相同的。 在 iOS 和 Mac OS X v10.5 及更高版本中,所有对象
我有一个 C++ 类方法,我需要用所有参数调用“detachNewThreadSelector”方法。 这就是问题所在,因为我的类(class)不是 Objective-C 我没有自指针。我也不知道如
我是一名优秀的程序员,十分优秀!