[英]Stop activityIndicator in Embedded TableView Cell Upon Return From Detail ViewController
I have a viewController that has a container view. 我有一个具有容器视图的viewController。 In the container view I have a tableView that contains static cells.
在容器视图中,我有一个包含静态单元格的tableView。 Each cell has a disclosure indicator.
每个单元都有一个公开指示器。 This was all created in IB.
这都是在IB中创建的。 The parent viewController is embedded in a navigationController.
父viewController嵌入在navigationController中。
Each cell pushes a new view controller which loads a mapView. 每个单元都推送一个新的视图控制器,该控制器将加载mapView。 Each map parses and loads a .kml file.
每个映射都解析并加载一个.kml文件。 The .kml files are huge and take up to a minute (or more) to load.
.kml文件非常大,最多需要一分钟(或更多)来加载。
I placed an activityIndicator in the accessory view of each cell using the following code: 我使用以下代码在每个单元格的附件视图中放置了一个activityIndicator:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *activityView =
[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activityView startAnimating];
[cell setAccessoryView:activityView];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];}
This appears to work as expected. 这似乎按预期工作。
After viewing the map I touch the "back" button provided by the navigationController and pop the map off the stack. 查看地图后,我触摸由navigationController提供的“后退”按钮,然后将地图弹出堆栈。 My embedded tableView is visible again, with the activity indicator still spinning.
我的嵌入式tableView再次可见,活动指示器仍在旋转。 I can't get it to stop.
我无法阻止它。
My best attempt was in the implementation file of my tableView: 我的最佳尝试是在tableView的实现文件中:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[[self tableView] reloadData];}
But that didn't work. 但这没有用。 Any suggestions?
有什么建议么?
Calling reloadData
in the table view controller's viewWillAppear
would work as long as in the cellForRowAtIndexPath
method, you're setting the state for UIActivityIndicatorView
by calling it's stopAnimating
method (or simply remove it from the view) for any cell that shouldn't be spinning. 只要在
cellForRowAtIndexPath
方法中调用表视图控制器的viewWillAppear
中的reloadData
,您可以通过对不应该旋转的任何单元stopAnimating
用它的stopAnimating
方法(或直接从视图中删除它)来设置UIActivityIndicatorView
的状态。
You'll need to reference the activity indicator via the accesstoryView
property. 您需要通过
accesstoryView
属性引用活动指标。
In your data, you could store a property that indicates whether the indicator should still be spinning for that map and set it appropriately. 在数据中,您可以存储一个属性,该属性指示指标是否仍应针对该地图旋转,并进行适当设置。
Another method would be to stop the activity indicator in prepareForSegue
, just prior to showing the map view. 另一种方法是在显示地图视图之前停止在
prepareForSegue
的活动指示器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.