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?
是的,你說得對。謝謝 ! –
@ profidash_98好的...如果你有任何問題,請聯繫 –
好的,謝謝,但是效果很好 –