gpt4 book ai didi

ios - UIActivityIndi​​catorView在正确的时间显示

转载 作者:行者123 更新时间:2023-12-01 19:16:00 25 4
gpt4 key购买 nike

我正在制作一个允许用户在IOS应用程序中输入数据的表格。该表格允许用户输入很多重复的数据。因此,有时该过程需要时间,因此我想在此过程中显示UIActivityIndi​​catorView。

不幸的是,微调器在过程结束时只出现一秒钟或更短的时间,而不是在预期的开始时出现。

有一些代码:

- (void) manageSpinner{
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[spinner setCenter:CGPointMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0)]; // I do this becau I'm in landscape mode
UIImageView *imageView = [[UIImageView alloc]initWithFrame:self.tableView.bounds];
UIImage *image = [UIImage imageNamed:@"dark_gradiant.jpg"];
[imageView setImage:image];
[imageView addSubview:spinner];
[self.tableView addSubview:imageView];
[spinner startAnimating];
}


//On click save by the user
- (IBAction)save:(id)sender{

//Collect information from the form

myObject.name = nameTF.text;

[...]

if(informations OK[...]){
//Manage spinner
[self manageSpinner];

//Add : this is the long process
for (int i=0; i<nbRepeatChooseByUser; i++) {
[myObject register];
}

//Call the delegate that will dismiss the form
[self.delegate theSaveButtonOnTheAddMyObjectTVCWasTapped:self];
}
}

微调器是在添加方法之前调用的,但似乎是在该过程之后设置的。

谢谢,

亚历山大(Alexandre)

最佳答案

Activity 指示器与您的长进程在同一线程上运行,因此动画不会按您希望的那样立即开始。尝试在后台线程中运行您的长进程。

if(informations OK[...]){        
//Manage spinner
[self manageSpinner];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
// Do your background process here
//Add : this is the long process
for (int i=0; i<nbRepeatChooseByUser; i++) {
[myObject register];
}

dispatch_async(dispatch_get_main_queue(), ^{
//This section will be called after your long process has been completed.

//Call the delegate that will dismiss the form
[self.delegate theSaveButtonOnTheAddMyObjectTVCWasTapped:self];
});

});

}

关于ios - UIActivityIndi​​catorView在正确的时间显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13306794/

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