Iphone uitableview应该在使用大量数据从webservice中检索数据后加载
我要求UITableview在从web服务检索数据后加载数据。检索海量数据时,我的uitableview显示为空。相反,UIActivityIndicator应该出现,直到数据加载到UITableview 我尝试如下,但无法获得所需的功能。请帮忙 另外,当从webservice返回的数据非常庞大时,我建议将数据加载到UITableview的最佳方法是什么 提前谢谢Iphone uitableview应该在使用大量数据从webservice中检索数据后加载,iphone,web-services,uitableview,Iphone,Web Services,Uitableview,我要求UITableview在从web服务检索数据后加载数据。检索海量数据时,我的uitableview显示为空。相反,UIActivityIndicator应该出现,直到数据加载到UITableview 我尝试如下,但无法获得所需的功能。请帮忙 另外,当从webservice返回的数据非常庞大时,我建议将数据加载到UITableview的最佳方法是什么 提前谢谢 - (UITableViewCell *)tableView: (UITableView *)tableView cellForRo
- (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文件,解压缩此文件。您将获得两个.h和.m用于加载指示器视图,。将其拖放到项目中 现在您可以像下面这样使用:- 如果您希望在未加载数据之前显示活动指示器:-
将LoadingView.h导入类中
创建对象
loadingView=[loadingView-loadingView-inview:self.view:@“请稍候…”代码>
此时,将此代码放在类似olsoyourTableView.userInterfaceEnable=FALSE的位置代码>
在数据加载完成方法中
[loadingView removeFromSuperview]代码>
yourTableView.userInterfaceEnable=TRUE代码>
您将获得如下加载视图:-
更新
它不会首先执行TableView委托
1)如果使用NSURLConnection
进行分区Web服务,则可以在加载完成后重新加载TableView数据:-
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//your code
[yourTableView reloadData];
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
//your code
[yourTableView reloadData];
}
2)如果您使用NSXMLParser
来解析Web服务,您可以在加载完成后重新加载TableView数据:-
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//your code
[yourTableView reloadData];
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
//your code
[yourTableView reloadData];
}
我的朋友在完成加载委托时重新加载数据方法可能是您使用NSURLconnection来处理pars数据,对吗?谢谢@Nitin Gohel,您还可以建议将大量数据从webservice加载到UITableview的最佳方法吗。在viewDidLoad()中,我正在将数据加载到数组中。但是,tableview委托方法首先执行。@NitinGohel当我打开选项卡栏时,我没有在tableview中获取数据。它显示在控制台中,但不显示在tableview中。我还重新加载了tableview。