Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 取消NSThread_Ios_Iphone_Objective C - Fatal编程技术网

Ios 取消NSThread

Ios 取消NSThread,ios,iphone,objective-c,Ios,Iphone,Objective C,以下是我创建线程的方式: readFromWebThread = [[NSThread alloc] initWithTarget:self selector:@selector(loadThread:) object:urlStr]; 我就是这样阻止它的: if ([readFromWebThread isExecuting]) { [readFromWebThread cancel]; } 这就是我在线程中执行的: -(void)loadThread:(NSString*)url

以下是我创建线程的方式:

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 thread方法,线程也会继续调用。 你知道什么是错误吗?

来自文档:

-取消:“更改接收器的已取消状态,以指示它应退出。”

==>您必须执行线程的取消!如果它睡着了,它永远不会被取消

e、 g

从文档中:

-取消:“更改接收器的已取消状态,以指示它应退出。”

==>您必须执行线程的取消!如果它睡着了,它永远不会被取消

e、 g

从文档中:

-取消:“更改接收器的已取消状态,以指示它应退出。”

==>您必须执行线程的取消!如果它睡着了,它永远不会被取消

e、 g

从文档中:

-取消:“更改接收器的已取消状态,以指示它应退出。”

==>您必须执行线程的取消!如果它睡着了,它永远不会被取消

e、 g


-取消
仅设置一个标志。你必须检查旗子

while (!self.isCancelled) {
    // MyStuff
}

-取消
仅设置一个标志。你必须检查旗子

while (!self.isCancelled) {
    // MyStuff
}

-取消
仅设置一个标志。你必须检查旗子

while (!self.isCancelled) {
    // MyStuff
}

-取消
仅设置一个标志。你必须检查旗子

while (!self.isCancelled) {
    // MyStuff
}
对OP的注释:“如果它睡着了,它就永远不会被取消。不要只睡它”对OP的注释:“如果它睡着了,它就永远不会被取消。不要只睡它”对OP的注释:“如果它睡着了,它就永远不会被取消。不要只睡它”