简体   繁体   English

从明细视图控制器返回后,在嵌入式TableView单元格中停止activityIndi​​cator

[英]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: 我使用以下代码在每个单元格的附件视图中放置了一个activityIndi​​cator:

- (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.

相关问题 目标c TableView单元格详细信息ViewController - objective c TableView cell Detail ViewController UICollectionView嵌入在UITableViewCell中! 无法从tableview单元格显示ViewController! 回电 - UICollectionView embedded in a UITableViewCell ! Cannot present a viewcontroller from the tableview cell ! With a call back [以编程方式]选择嵌入在 collectionView 单元格中的 tableView 行时推送 viewController - [Programmatically]Push a viewController when selecting tableView row embedded in a collectionView cell 如何从xib tableview Cell推送ViewController? - how to push ViewController from xib tableview Cell? 从另一个 ViewController 重新分配 TableView 单元格变量 - Reassign TableView Cell Variable from another ViewController 将详细信息从tableView的自定义单元格传递到detailView - Passing detail from a custom cell in a tableView to a detailView 如何在Swift中从Detail ViewController更新tableview数组 - How to update array of tableview from Detail ViewController in Swift 我如何将数据从SlideTableTableViewController传递到ViewController中嵌入的TableView - How i pass Data from SlideOut TableViewController to TableView embedded in ViewController 如何在目标C中将图像从主viewController设置为tableView单元格? - How to set image from main viewController to tableView cell in objective C? 从选择TableView单元格丢失参考加载的ios Swift ViewController - ios Swift ViewController Loaded from Selecting TableView Cell Loses Reference
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM