我有一个封面流,它有3个不同的图像集。其中一个需要生成,我一直在试图让它填充一个线程,用于更大的图像选择。NSThread被称为第二次(在第一次没有完成后)得到“EXC_BAD_ACCESS”
这里有点我的代码:
- (void) startSongThread {
[NSThread detachNewThreadSelector:@selector(songThreadMain) toTarget:self withObject:nil];
}
- (void) songThreadMain {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int i = 0;
while(i < [items count] && ![[NSThread currentThread] isCancelled]) {
NSNumber *nsInt = [NSNumber numberWithInt:i];
if(![addedSongIndexes containsObject:nsInt]) [self setSongImage:nsInt];
i++;
}
[pool release];
}
- (void) stopSongThread {
if(![[NSThread currentThread] isCancelled]) [[NSThread currentThread] cancel];
}
的图像时,从一种类型更改为另一stopSongThread方法被调用。
如果我加载所有的主要图像,切换图像集,然后切换回主集我总是得到EXC_BAD_ACCESS。
我试图分配线程,但它只能工作一次以及..如果我让它加载并且不要试图阻止它,它的工作很好。
任何帮助wuld是伟大的,谢谢!
你会得到什么错误的访问错误? – 2010-09-10 01:30:48
每次都有所不同,具体取决于何时切换并尝试停止线程。 – 2010-09-10 15:38:05