繁体   English   中英

uitableview应该在从Web服务检索海量数据后加载

[英]uitableview should load after retreving data from webservice with huge data

我有一个要求,我的UITableview应该在从Web服务检索数据之后加载数据。 检索大量数据时,我的uitableview显示为空。 取而代之的是,应该显示一个UIActivityIndi​​cator,直到将数据加载到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];

}

嗨,下载此zip http://www.sendspace.com/file/l48jxg将此文件解压缩,您将获得两个.h.m来加载Indicatore视图。 将此拖放到您的项目中。

现在,您可以像Bellow这样使用它:

如果您希望显示活动指示器,直到您的数据没有加载:-

import LoadingView.h into your Class

创建对象

loadingView =[LoadingView loadingViewInView:self.view:@"Please Wait.."]; 此时,将这段代码像yourTableView.userInterfaceEnable=FALSE;

然后在数据加载完成方法中

[loadingView removeFromSuperview];

yourTableView.userInterfaceEnable=TRUE;

您正在加载视图,例如:

在此处输入图片说明

更新

它不会满足您首先执行的TableView委托。

1)如果您将NSURLConnection用于Parsiong Web服务,则可以在加载完成后在以下位置重新加载您的TableView数据:-

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {


    //your code
    [yourTableView reloadData];

}

2)如果您将NSXMLParser用于Parsiong Web服务,则可以在加载完成后在以下位置重新加载TableView数据:

- (void)parserDidEndDocument:(NSXMLParser *)parser 
{

    //your code
    [yourTableView reloadData];
}

尝试使用此活动指示器,该指示器将停止用户交互,直到加载数据为止。

使用github上可用的MBProgressHud

祝您编码愉快。

暂无
暂无

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

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