2014-02-23 65 views
1

我想在從JSON加載一些數據時創建一個UIProgressView。 那是我使用來獲取JSON數據的代碼:JSON加載ProgressView

-(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]; 
    } 

} 

誰能幫我創建一個顯示當前下載進度progressview?

回答

1

您可以使用MBProgressHud
當你想添加/顯示進度HUD對你的看法只是調用

[MBProgressHUD showHUDAddedTo:self.view animated:YES];

那麼對於隱藏/停止您可以撥打

[MBProgressHUD hideHUDForView:self.view animated:YES];

+0

是的,你說得對。謝謝 ! –

+0

@ profidash_98好的...如果你有任何問題,請聯繫 –

+0

好的,謝謝,但是效果很好 –