我有一個要求,我的UITableview應該從Web服務檢索數據後加載數據。當檢索大量數據時,我的uitableview顯示爲空。相反,UIActivityIndicator應該出現,直到數據加載到UITableview中。uitableview應該加載後,從大量的數據從webservice中刪除數據
我想如下,但無法獲得所需的功能。請幫忙。
另外,讓我建議什麼是最好的方法來加載數據到UITableview,當從webservice返回的數據是巨大的。
在此先感謝。
- (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];
}
我的朋友重新加載數據在完成加載委託方法可能是你使用NSURLconnection權限的數據庫嗎? – 2013-02-22 05:11:13