简体   繁体   English

在通过Segue之前显示活动指示器

[英]Show Activity Indicator before passing Segue

Ok my First Controller is a UITabel and when a cell is passed it pushes to the Second View Controller. 好的,我的第一个控制器是UITabel,当传递一个单元格时,它将推送到第二个视图控制器。 The Second Controller loads data from a webservice so the segue takes a little. 第二个控制器从Web服务加载数据,因此花费了一些时间。 I would like to show a SVProgressHUD when the cell is selected and then dismiss it after the data loaded but the SVProgressHUD instead shows after the Second View is loaded and only for aa couple milliseconds.I use this right now: 我想在选中单元格时显示SVProgressHUD,然后在加载数据后将其关闭,但是SVProgressHUD却在第二视图加载后显示,并且仅显示了几毫秒。我现在使用此方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [SVProgressHUD show];
    UITableViewCell *acell = [tableView cellForRowAtIndexPath:indexPath];
    [self performSegueWithIdentifier:@"pushCell" sender:acell];
}

Any way to show the SVProgressHUD immediately when cell is selected? 有什么方法可以在选择单元格后立即显示SVProgressHUD?

Apple recommends that when the user clicks on a tableViewCell the app should segue to the next view controller immediately. Apple建议当用户单击tableViewCell时,应用程序应立即选择到下一个视图控制器。 The fact that you feel you need to show a SVProgressHUD while the next view loads suggests to me that you are requesting the data using a synchronous method, which will block the main thread and make it appear that your app has frozen while it waits for the response. 您认为在下一个视图加载时需要显示SVProgressHUD的事实向我表明,您正在使用同步方法来请求数据,这将阻塞主线程,并使其在等待应用程序时似乎已冻结。响应。

The best practice for retrieving data is to always do so asynchronously (or on a background thread) so that your app always remains responsive. 检索数据的最佳实践是始终异步(或在后台线程上),以便您的应用始终保持响应状态。 I would recommend changing your request to an asynchronous method (look into the NSURLRequest method initWithRequest:delegate: , for example). 我建议将您的请求更改为异步方法(例如,查看NSURLRequest方法initWithRequest:delegate: :)。 If you use that you can then show the SVProgressHUD in your second controller's viewDidLoad method, the transition to the second view controller will happen instantly when the user taps the table cell, and your app won't be locked up while the user waits for the data to download. 如果您使用它,然后可以在第二个控制器的viewDidLoad方法中显示SVProgressHUD,则当用户点击表格单元格时,将立即发生向第二个视图控制器的转换,并且在用户等待输入时不会锁定您的应用程序数据下载。

Here is more info about this method from the Apple Documentation 以下是Apple文档中有关此方法的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM