从Web服务获取用户特定数据以填充UITableView

时间:2011-04-19 08:08:38

标签: iphone web-services uitableview viewdidload

我试图在用户登录应用程序后,从Web服务中为特定用户(他的项目)填充UITableView数据。

例如:

tableData = [[NSMutableDictionary alloc] initWithCapacity:DICTIONARY_INITIAL_CAPACITY];
//CURRENT PROJECT
 //get the information from the server
 NSArray *currentProject = [[IHMObjectFinderServices sharedIHMObjectFinderServices]     getCurrentProjectAsArray:connectedUserId];
 if(![currentProject isEqual:[NSNull null]]) {
     //put the info in a dictionnary
     NSMutableDictionary *currentProjectDictionary = [[NSMutableDictionary alloc] initWithCapacity:PROJECT_DICTIONARY_CAPACITY];
     [currentProjectDictionary setObject:[currentProject objectAtIndex:INDEX_PROJECT_NAME] forKey:KEY_PROJECT_NAME];
     [currentProjectDictionary setObject:[currentProject objectAtIndex:INDEX_PROJECT_MANAGER] forKey:KEY_PROJECT_MANAGER];
     [currentProjectDictionary setObject:[currentProject objectAtIndex:INDEX_PROJECT_TAG] forKey:KEY_PROJECT_TAG];
     NSArray *activitiesForProject = [NSArray arrayWithArray:[[IHMObjectFinderServices sharedIHMObjectFinderServices] getAvailableActivities:[currentProjectDictionary valueForKey:KEY_PROJECT_TAG]]];
     [currentProjectDictionary setObject:activitiesForProject forKey:KEY_PROJECT_ACTIVITIES];

     [tableData setObject:currentProjectDictionary forKey:KEY_CURRENT_PROJECT];

目前,我的表在viewDidLoad方法中加载,因此问题是在构造表时用户尚未连接。

我已经阅读了有关reloadData方法但我不确定如何在用户登录后继续加载表一次。有人可以向我解释一下这是正确的程序吗?

感谢您的帮助, 迈克尔

1 个答案:

答案 0 :(得分:0)

当tableView的数据可用时,应该有某种回调方法。只需将reloadData放入其中即可。

- (void)dataIsAvailable
{
     // ... your code to set the tableData ...

     [self.tableView reloadData];
}