gpt4 book ai didi

ios - 使用 NSTimer 调用 performSelectorOnMainThread

转载 作者:行者123 更新时间:2023-11-29 12:50:35 25 4
gpt4 key购买 nike

我可以在下面的行中调用 pushIncompleteDataToServer

[sharedDataController performSelectorOnMainThread:@selector(pushIncompleteDataToServer) 
withObject:sharedDataController
waitUntilDone:NO].

现在我想用 NSTimer 以 5.0 秒的间隔调用它

[NSTimer scheduledTimerWithTimeInterval:5.0 
target:sharedDataController
selector:@selector(**pushIncompleteDataToServer**)
userInfo:[ self userInfo]
repeats:YES];

我想调用 performSelectorOnMainThread(第一条语句中的内容),而不是 pushIncompleteDataToServer。如何做到这一点?

最佳答案

这样做

[NSTimer scheduledTimerWithTimeInterval:5.0 
target:sharedDataController
selector:@selector(pushData)
userInfo:[ self userInfo]
repeats:YES];


-(void)pushData {
[sharedDataController performSelectorOnMainThread:@selector(pushIncompleteDataToServer)
withObject:sharedDataController
waitUntilDone:NO].

}

关于ios - 使用 NSTimer 调用 performSelectorOnMainThread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22526459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com