我需要顯示一個UIActivityIndicator,而我正在等待Web服務的響應。我到底在哪裏把它的代碼?它不以這種方式工作。活動指示器不顯示。調用webservice時顯示UIActivityIndicator
我是否需要使用異步請求才能顯示它?
-(void)callWebService
{
[self.customercareSearchbar resignFirstResponder];
[self.SRResultDictionary removeAllObjects];
NSLog(@"web service called");
NSString *srn = _SRNumber;
NSString *serviceURL = [NSString stringWithFormat:@"https://abcdef...];
@try {
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:activity];
activity.center = self.view.center;
[self.view bringSubviewToFront:loadView];
activity.hidesWhenStopped = YES;
[activity setHidden:NO];
[activity startAnimating];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:serviceURL]];
NSURLResponse *serviceResponse = nil;
NSError *err = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&serviceResponse error:&err];
[activity stopAnimating];
NSMutableDictionary *parsedData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&err];
if(!parsedData)
{
NSLog(@"data not parsed");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Problem in Network. Please Try Again!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[self.customerCareTableView setHidden:YES];
}
else
{
NSLog(@"parsed");
NSLog(@"parsed.. the size is %lu", (unsigned long)[parsedData count]);
NSLog(@"%@", parsedData);
NSString *status = [parsedData objectForKey:@"ns:Status"];
NSLog(@"the status is %@", status);
if([status isEqualToString:@"Success"])
{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if([[prefs objectForKey:@"SwitchState"] isEqualToString:@"OFF"])
{
//do nothing
}
else
{
[self saveNumberInDatabase:srn];
}
NSMutableDictionary *third = [parsedData objectForKey:@"ListOfXrxLvServiceRequest"];
NSLog(@"internal dict is %@", third);
self.SRResultDictionary = [third objectForKey:@"ServiceRequest"];
[self.customerCareTableView reloadData];
[self.customerCareTableView setHidden:NO];
}
else if([status isEqualToString:@"Record Not Found"])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Entry" message:@"Please enter a valid Service Request Number" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[self.customerCareTableView setHidden:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"ERROR" message:@"Problem in Network. Please Try Again!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[self.customerCareTableView setHidden:YES];
}
}
}
@catch (NSException *exception)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NULL message:@"Problem In Network Connection. Please Try Again!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[self.customerCareTableView setHidden:YES];
}
@finally {
}
}
這是最好的[MBProgressHUD(https://github.com/jdg/MBProgressHUD) –
請。這人想知道如何以及何時使用UIActivityIndicator。你爲什麼把他引導到第三方?教他吧。笏是問題的人。笏完全正在發生,當你使用你自己的代碼? – croyneaus4u
活動指標不顯示當我使用我的代碼.. – Shradha