我就是这样创建线程的:
readFromWebThread = [[NSThread alloc] initWithTarget:self selector:@selector(loadThread:) object:urlStr];我就是这样阻止它的:
if ([readFromWebThread isExecuting]) {
[readFromWebThread cancel];
}这就是我在这个帖子中所表现出来的:
-(void)loadThread:(NSString*)urlStr {
while (YES) {
//MyStuff
[NSThread sleepForTimeInterval:kSleepBetweenLoading];
}
}问题是,甚至调用线程一直调用的cancel线程方法。你知道什么是错误吗?
发布于 2014-01-23 13:47:04
从医生那里:
-cancel:“更改接收方被取消的状态以指示它应该退出。”
==>您必须实现线程的取消!如果它睡着了,它就永远不会被取消
例如:
while(YES) {
//do a piece of work
if([NSThread currentThread].state == canceled)
break;
}发布于 2014-01-23 13:48:19
-cancel只是设置了一个标志。你得检查旗子。
while (!self.isCancelled) {
// MyStuff
}https://stackoverflow.com/questions/21309373
复制相似问题