[英]How can I cancel or stop thread when back button is pressed?
我最近几天一直在使用线程。我想在按导航栏中的后退按钮时停止线程。但是我找不到停止该后台线程的解决方案。如果有人知道,请帮帮我。
If you have done like this to run a function in background ie 如果您这样做是在后台运行功能,即
[self performSelectorInBackground:@selector(myFunction) withObject:nil];
then to cancel it you can use this code 然后要取消它,您可以使用此代码
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(myFunction) object:nil];
您可以NSOperation
并轮询isCancelled
属性以停止线程运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.