我有一个要求,我的 UITableview 应该在从 Web 服务检索数据后加载数据。检索大量数据时,我的 uitableview 显示为空。取而代之的是,一个 UIActivityIndicator 应该出现,直到数据加载到 UITableview 中。
我正在尝试如下,但无法获得所需的功能。请帮忙。
当从 web 服务返回的数据很大时,我还建议将数据加载到 UITableview 中的最佳方法是什么。
提前致谢。
- (UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
UILabel *lblName = (UILabel *)[cell viewWithTag:1];
[lblName setText:[myArray objectAtIndex:[indexPath row]]];
return cell;
}
- (void)dataLoading
{
myActivityIndicator=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[myActivityIndicator setFrame:CGRectMake(140, 170, 40, 40)];
[self.view addSubview:myActivityIndicator];
[myActivityIndicator startAnimating];
NSString *playersDatalink = [NSString stringWithFormat:@"Webservice link"];
NSURL *JsonPlayersDataURL = [NSURL URLWithString:playersDatalink];
NSString *JsonPlayersData = [[NSString alloc] initWithContentsOfURL:JsonPlayersDataURL];
SBJSON *playersDataParser = [[SBJSON alloc] init];
NSDictionary *PlayersDicdata = (NSDictionary *) [playersDataParser objectWithString:JsonPlayersData error:nil];
NSDictionary *playersdata = (NSDictionary *) [PlayersDicdata objectForKey:@"players"];
NSLog(@"palyersdata is =%@",playersdata);
self.myArray = [NSMutableArray arrayWithCapacity:[playersdata count]];
for (NSDictionary *details in playersdata) {
[self.myArray addObject:[details objectForKey:@"teamid"]];
}
if ([playersdata count]==0) {
UIAlertView *myalert = [[UIAlertView alloc]initWithTitle:@"Webserive error " message:@"No data returned from webservice" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[myalert show];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self performSelector:@selector(dataLoading) withObject:nil afterDelay:0.0];
[myActivityIndicator stopAnimating];
}