简体   繁体   English

数据加载-在tableview上启动应用程序

[英]data loading - app launching on tableview

i encounter an issue with my application. 我的应用程序遇到问题。

On one hand when my app launches, the first view displayed is a tableview within a tableviewcontroller. 一方面,当我的应用启动时,显示的第一个视图是tableviewcontroller中的一个tableview。

On the other hand my app calls a web service to collect data. 另一方面,我的应用程序调用网络服务来收集数据。 These methods are in MyAppDelegate\\applicationDidFinishLaunching. 这些方法位于MyAppDelegate \\ applicationDidFinishLaunching中。

The thing is that my tableview is made of custom cells that need data from the web service. 事实是,我的表视图是由需要来自Web服务的数据的自定义单元构成的。

I noticed that the view (with the tableview) is launched first and then MyAppDelegate\\applicationDidFinishLaunchin is executed. 我注意到该视图(带有tableview)首先启动,然后执行MyAppDelegate \\ applicationDidFinishLaunchin。

As a result the labels of my custom cells are all equal to null as my arrays aren't filled yet by the web service. 结果,我的自定义单元格的标签都等于null,因为Web服务尚未填充我的数组。

I would like to know the proper way to make it. 我想知道正确的制作方法。

If anyone has an idea please tell me. 如果有人有主意请告诉我。

Wallou 瓦卢

Use NSNotificationCenter to communicate to your UITableViewController that it needs to reloadData for the table. 使用NSNotificationCenter向您的UITableViewController传达需要重新加载表的数据。

To Register (in your UITableViewController.viewDidLoad): 要注册(在您的UITableViewController.viewDidLoad中):

[[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(dataLoaded:)
    name:@"myapp.dataloaded" object:nil];

- (void)dataLoaded:(NSNotification *)notification
{
    [self.table reloadData];
}

To post notifications (after you loaded the data): 要发布通知(在加载数据之后):

[[NSNotificationCenter defaultCenter]
    postNotificationName:@"myapp.dataloaded" object:nil];

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

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