gpt4 book ai didi

ios - 带有 Spinner 的 iOS 中的 sleep 功能

转载 作者:行者123 更新时间:2023-11-29 02:01:22 26 4
gpt4 key购买 nike

我有一个微调函数来从流程的开始到结束启动和停止。但由于过程需要几毫秒,我真的无法让微调器转动。

[NSThread sleepForTimeInterval:2.0]; //method 1
sleep(2); //method2

然后我使用 Sleep 方法使代码处于待机状态并让微调器转动,但它停止了线程,然后微调器也将停止。这是代码:

if (indexPath.row == 1)
{
[MBProgressHUD showHUDAddedTo:self.view animated:YES]; //spinner starts

EmployeeDataSource *aaa=[[EmployeeDataSource alloc]init];
[aaa Logout: ^(BOOL results){
if(results == YES){

[NSThread sleepForTimeInterval:2.0]; //sleeping thread

//if logout succesfull go to login page
LoginViewController *lv = [self.storyboard instantiateViewControllerWithIdentifier:@"loginsb"];

[self presentViewController:lv animated:NO completion:nil];

[MBProgressHUD hideAllHUDsForView:self.view animated:YES]; //spinner ends

}
else{

NSLog(@"logout not succesfull");
}
}];

我希望[MBProgressHUD showHUDAddedTo:self.viewanimated:YES];至少工作2秒,但由于正常过程很快,所以它会在不到一秒的时间内结束?我怎么能延长这个时间, sleep 方法似乎不合适。你有什么主意吗?谢谢。

最佳答案

我认为你应该在延迟一段时间后做你的事情。为此请使用这个

[self performSelector:@selector(method) withObject:nil afterDelay:1.0];

这里的Delay是以秒为单位的,所以你可以相应地设置它。

或者你也可以这样做。

dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//Do you stuff here...
});

愿这对您有帮助。

关于ios - 带有 Spinner 的 iOS 中的 sleep 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30344077/

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