簡體   English   中英

按下后退按鈕時如何取消或停止線程?

[英]How can I cancel or stop thread when back button is pressed?

我最近幾天一直在使用線程。我想在按導航欄中的后退按鈕時停止線程。但是我找不到停止該后台線程的解決方案。如果有人知道,請幫幫我。

如果您這樣做是在后台運行功能,即

[self performSelectorInBackground:@selector(myFunction) withObject:nil];

然后要取消它,您可以使用此代碼

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(myFunction) object:nil];

您可以NSOperation並輪詢isCancelled屬性以停止線程運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM