我正在构建一个文章阅读应用程序。我正在使用 AMSliderMenu( https://github.com/SocialObjects-Software/AMSlideMenu ) 菜单列表库。
我无法实现 UIActivityIndicator
,当我点击 AMSlideMenu 中的表格单元格时,加载另一个 View 需要时间,因为数据正在加载到另一个 View 中。
我想在用户单击单元格 UIActivityIndicator
时提供 UIActivityIndicator
执行,直到它打开另一个 View 。
这是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake(160, 240);
spinner.hidesWhenStopped = YES;
[self.view addSubview:spinner];
[spinner startAnimating];
dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL);
dispatch_async(downloadQueue, ^{
[NSThread sleepForTimeInterval:10];
dispatch_async(dispatch_get_main_queue(), ^{
[spinner stopAnimating];
});
});
NSString *segueIdentifier = [self.mainVC segueIdentifierForIndexPathInLeftMenu:indexPath];
if (segueIdentifier && segueIdentifier.length > 0)
{
[self performSegueWithIdentifier:segueIdentifier sender:self];
}
}
最佳答案
在类级别范围内声明 UIActivityIndicatorView
。
UIActivityIndicatorView *spinner;
在主队列中执行segue:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake(160, 240);
spinner.hidesWhenStopped = YES;
[self.view addSubview:spinner];
[spinner startAnimating];
dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL);
dispatch_async(downloadQueue, ^{
[NSThread sleepForTimeInterval:10];
dispatch_async(dispatch_get_main_queue(), ^{
NSString *segueIdentifier = [self.mainVC segueIdentifierForIndexPathInLeftMenu:indexPath];
if (segueIdentifier && segueIdentifier.length > 0){
[self performSegueWithIdentifier:segueIdentifier sender:self];
}else{
[spinner stopAnimating];
}
});
});
}
在进行 segue 时停止微调器:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
[spinner stopAnimating];
}
关于ios - 如何在执行 segue 期间使用 UIActivityIndicatorView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25666115/