Ios开发:终止子线程

2024-10-15 07:36:42

1、新建一个single view application,在程序界面添加一个停止按钮(button),并为该按钮的touch up inside绑定cancelThread事件处理方法,如图

Ios开发:终止子线程

3、点击run运行,运行结果如下

Ios开发:终止子线程

5、主要程序讲解:[thread cancel]该方法用于向thread对象发送取消信号[NSThread currentThread].isCancelled返回值为yes,调用 [NSThread exit]终止当前正在执行的循环

Ios开发:终止子线程
猜你喜欢