当我从JSON加载一些数据时,我想创建一个UIProgressView。 这就是我用来获取JSON数据的代码:
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == searchTextField)
{
[searchTextField resignFirstResponder];
[self loadData];
}
return YES;
}
-(void)loadData
{
NSString *urlString = [NSString stringWithFormat:@"mydomain.com/search/getEvents.php?searchQuery=%@", searchTextField.text];
NSURL *searchURL = [NSURL URLWithString:urlString];
dispatch_async(kBgQueue, ^{
NSData *data = [NSData dataWithContentsOfURL:searchURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
-(void)fetchedData:(NSData*)responseData
{
NSError *error;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
[fetchedResutsArray release]; // release old instance
fetchedResutsArray = [[json objectForKey:@"Events"] retain];
NSLog(@"%@", fetchedResutsArray);
if (fetchedResutsArray != nil)
{
[self.tableView reloadData];
}
else if (fetchedResutsArray == nil)
{
UIAlertView *noResultsAlert = [[UIAlertView alloc] initWithTitle:@"No Results" message:@"There are no results" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[noResultsAlert show];
[noResultsAlert release];
}
}
有人可以帮我创建一个显示当前下载进度的进度视图吗?
答案 0 :(得分:1)
您可以使用MBProgressHud
当您想要在视图中添加/显示进度hud时,请拨打
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
然后,对于隐藏/停止,您可以拨打
[MBProgressHUD hideHUDForView:self.view animated:YES];