简体   繁体   English

在rootViewController中重新加载tableView数据

[英]Reload tableView data in rootViewController

I am trying to get my tableView in rootViewController to reload after I create a new object in the array that populates it. 我试图在填充它的数组中创建一个新对象后,在rootViewController中重新加载tableView。

I want to use the following in my viewDidLoad of rootVIewController: 我想在rootVIewController的viewDidLoad中使用以下内容:

[tableView reloadDate];

but I get the error: 但是我得到了错误:

Use of undeclared identifier "tableView"

I think it's because I haven't declared the object tableView until after the viewDidLoad method. 我认为这是因为直到viewDidLoad方法之后,我才声明对象tableView。 So what other options do I have to refresh the table? 那么,我还需要刷新表的其他哪些选项?

Thanks 谢谢

If you haven't declared the tableView, than you cannot tell it to reload. 如果尚未声明tableView,则无法告诉它重新加载。 There is something of a question surrounding the architecture of your application: When you say 'rootViewCOntroller' - is that referring to the applications RVC? 围绕您的应用程序体系结构存在一些问题:当您说“ rootViewCOntroller”时-是指应用程序RVC吗? If so, are you instantiating the tableView programmatically, or accessing it from a .xib/outlet? 如果是这样,您是通过编程方式实例化tableView还是从.xib /插座访问它?

If you're accessing a XIB, you should be calling your property outlet [[self tableView] reloadData]. 如果要访问XIB,则应调用属性出口[[self tableView] reloadData]。

If you're creating the table view programmatically, you should create it before you call reload on it -- and in most cases, you'll want to define a property on your RVC class pointing to that tableView, such that you'd still be calling [[self tableView] reloadData] as opposed to accessing it directly as you've done in your code. 如果要以编程方式创建表视图,则应在调用reload之前创建它-并且在大多数情况下,您将需要在RVC类上定义一个指向该tableView的属性,以便您仍然正在调用[[self tableView] reloadData],而不是像在代码中那样直接访问它。

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

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