如何在执行segue期间UIActivityIndicatorView?
问题描述:
我正在构建一篇文章阅读应用程序。我正在使用AMSliderMenu(https://github.com/SocialObjects-Software/AMSlideMenu) 库的菜单列表。如何在执行segue期间UIActivityIndicatorView?
我无法实施UIActivityIndicator
,当我在表上单击单元格AMSlideMenu需要一定的时间,因为数据加载到花药以加载另一个视图。
我想给UIActivityIndicator
当用户单击单元格UIActivityIndicator
执行直到它打开另一个视图的时间。
这里是我的代码:
- (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];
}
+0
非常感谢!美达,它的工作很好。 – Daljeet 2014-09-04 13:56:53
什么,当你按下一个细胞会发生什么?顺便说一句,考虑MBProgressHud https://github.com/jdg/MBProgressHUD。 – kelin 2014-09-04 13:16:56
为什么不使用MBProgressHUD?其中最好的 – sreekanthk 2014-09-04 13:27:42