简体   繁体   English

按下后退按钮时如何取消或停止线程?

[英]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.

相关问题 从我的应用程序拨打电话时,如何确定用户是按“呼叫”还是“取消”按钮? - How can I find out whether the user pressed the Call or the Cancel button when making a call from my app? 如何捕获iOS调试器中按下的“停止”按钮? - How can I capture the “Stop” button being pressed in the iOS debugger? 如何在按下按钮时播放音频,而当我将手指从同一按钮上移开时如何立即停止播放? - How can I make audio play when the button is pressed and immediately stop when I take my finger off the same button? 按下后退按钮时如何执行操作 - How do I perform an operation when the back button is pressed iOS,按下“后退”按钮时停止运行功能 - iOS, stop running a function when “back” button is pressed 如何判断在UINavigationControllerStack中按下后退按钮的时间 - How to tell when back button is pressed in a UINavigationControllerStack 按下时如何更改iPhone上按钮的默认颜色? - How can I change the default color of the button on iPhone when pressed? 按下按钮时停止动画 - stop animation when button is pressed 按下取消按钮时覆盖textFieldShouldEndEditing - override textFieldShouldEndEditing when cancel button pressed 如果按下子视图的按钮,如何取消 UIGestureRecognizer - How to cancel UIGestureRecognizer if subview's button pressed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM