Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.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
Objective c 在从后台线程中运行的方法调用的主线程上延迟执行选择器_Objective C_Multithreading_Nstimer_Background Process - Fatal编程技术网

Objective c 在从后台线程中运行的方法调用的主线程上延迟执行选择器

Objective c 在从后台线程中运行的方法调用的主线程上延迟执行选择器,objective-c,multithreading,nstimer,background-process,Objective C,Multithreading,Nstimer,Background Process,我有一个在后台运行的方法,通过调用 [self performSelectorInBackground:@selector(getTweets) withObject:nil]; “getTweets”调用包装类中的一个方法,该方法获取tweets并在tweets准备就绪时发布通知。我有一个观察者,当这种情况发生时,它会触发“showTweets” 当调用showTweets时,我想以5秒的延迟调用“hideTweets”。为此,我打电话: self.hideTweetTimer = [NST

我有一个在后台运行的方法,通过调用

[self performSelectorInBackground:@selector(getTweets) withObject:nil];
“getTweets”调用包装类中的一个方法,该方法获取tweets并在tweets准备就绪时发布通知。我有一个观察者,当这种情况发生时,它会触发“showTweets”

当调用showTweets时,我想以5秒的延迟调用“hideTweets”。为此,我打电话:

self.hideTweetTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self  selector:@selector(hideTweet) userInfo:nil repeats:NO];    
然而,它似乎没有开火。我还有一个按钮可以调用showTweets方法,但是当它被按下时,它似乎陷入了isHighlighted状态

由于最初的调用是在后台线程中,我是否做错了什么

我试过了

[[NSRunLoop currentRunLoop] addTimer:self.hideTweetTimer forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
这似乎可以隐藏推文,但这似乎会导致性能问题。例如,当我在另一个屏幕中加载UIScrollView时,滚动非常粘滞


基本上,我所有的问题似乎都源于在后台线程上执行某些操作,但我不确定是什么。。。非常感谢您的帮助。谢谢

您正在修改这些线程中的UI元素吗?唯一应该处理UI的线程是主线程。其他线程应该将它们的需求传达给主线程,而主线程实际上会为它们这样做

您可以使用以下命令将某些内容回调到主线程:

[self performSelectorOnMainThread:@selector(method) withObject:nil waitUntilDone:YES];