重新加载表格数据 [英] Reloading a table's data

查看:71
本文介绍了重新加载表格数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有5个视图控制器,它们位于导航控制器层次结构中.当我到达最后一个视图控制器时,有一个按钮可以让我返回到"Home"视图控制器(名为CardWalletViewController),它是一个表视图控制器.这是我上一个VC( PointsResultsVC )

I have 5 view controllers, which are in a navigation controller hierarchy. When I reach my last view controller, there's a button that lets me go back to the "Home" view controller (named CardWalletViewController) which is a table view controller. Here's the method I have in my last VC (PointsResultsVC)

- (IBAction)homePressed:(id)sender {
    NSArray *VCs = [self.navigationController viewControllers];
    [self.navigationController popToViewController:[VCs objectAtIndex:0] animated:YES];
}

CardWalletVC的单元格被来自NSUserDefaults中Card的已保存实例的值填充,并且工作正常.

CardWalletVC's cells is being filled up by values coming from the saved instances of a Card in NSUserDefaults and it works fine.

现在,我想要更新我的 CardWalletViewController 中的值,这是来自我的 PointsResultsVC 的卡片的点数.请注意,这些点保存在 NSUserDefault s中.

Now, what I want is to update the value in my CardWalletViewController, which is the points of a card coming from my PointsResultsVC. Note that this points is saved in NSUserDefaults.

在尝试更新CardWalletVC中显示的值的过程中,我在 -viewDidLoad -viewWillAppear中放置了 [self.tableView reloadData]; 和所述类的- viewDidAppear .我尝试在每种方法中将其一一放置,但似乎不起作用.

Upon the process of trying to update of the value shown in my CardWalletVC, I placed [self.tableView reloadData]; inside -viewDidLoad, -viewWillAppear, and -viewDidAppear of the said class. I tried placing it one by one in each of this methods, yet it doesn't seem to work.

请告知.

问题已解决

此指南为我的指南>从一个标签,然后在另一个标签中重新加载数据.

正如我发现的那样,在应用程序的整个运行过程中,某个类的 -viewDidLoad 只会被调用一次.而 -viewWillAppear ,则每次视图出现时都会调用它.

And as I have discovered, -viewDidLoad of a certain class will only be called once, all throughout runtime of app. Whereas -viewWillAppear, it will be called every time the view appears.

因此,我只是将将NSUserDefaults中保存的值从 -viewDidLoad 加载到 -viewWillAppear 的方式转移了.另外,在 -viewWillAppear 内部,放置了 [self.tableView reloadData] .然后在那里,问题解决了.

So, I just moved the way I am loading the values saved in NSUserDefaults from -viewDidLoad to -viewWillAppear. Also, inside -viewWillAppear I placed the [self.tableView reloadData]. Then there, problem solved.

推荐答案

可能会出现很多错误,因此您需要提供更多信息以缩小范围.

There's a lot of things that could be going wrong so you'll need to provide more info to narrow it down.

首先,不会调用viewDidLoad,因此您可以从此处删除它.viewWillAppear和viewDidAppear都将被调用,因此您只需要这两种方法之一.

First of all, viewDidLoad will not be called so you can remove it from here. Both viewWillAppear and viewDidAppear will be called, so you only need it one of these 2 methods.

接下来,您需要确定实际的问题是什么.

Next, you need to determine what the actual issue is.

1-self.tableView是对表的正确引用吗?您是否正确维护了参考?

1 - is self.tableView a proper reference to the table? Are you properly maintaining the reference?

2-该表实际上是在重新加载但正在使用旧数据,还是根本不重新加载?您可以记录willDisplayCell方法以查看视图出现时发生的情况.

2 - is the table actually reloading but using the old data, or is it not reloading at all? You can log the willDisplayCell method to see what is going on when the view appears.

有了这些信息,可以将根本原因缩小为可解决的问题.

With that info, the root cause can be narrowed down to a solvable problem.

这篇关于重新加载表格数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆