带有异步NSURLConnection调用的MBProgressHUD
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了带有异步NSURLConnection调用的MBProgressHUD相关的知识,希望对你有一定的参考价值。
- (void)setSearchingModeEnabled:(BOOL)isSearching { //when network action, toggle network indicator and activity indicator if (isSearching) { [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; UIWindow *window = [UIApplication sharedApplication].keyWindow; HUD = [[MBProgressHUD alloc] initWithWindow:window]; [window addSubview:HUD]; HUD.labelText = @"Connecting"; [HUD show:YES]; } else { [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; [HUD hide:YES]; [HUD removeFromSuperview]; [HUD release]; } } - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { [searchBar resignFirstResponder]; NSString *searchString = [searchBar.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; self.baseURL, searchType, searchString]; NSLog(@"connecting to: %@", searchURLString); //retrieve the json data [self setSearchingModeEnabled:YES]; [searchURLString release]; [searchURL release]; } #pragma mark - #pragma mark NSURLConnection Delegate Methods { [self.responseData setLength:0]; if ([self.searchResultFileSize intValue] != NSURLResponseUnknownLength) { HUD.mode = MBProgressHUDModeDeterminate; HUD.labelText = @"Getting Results"; } NSLog(@"content-length: %@ bytes", self.searchResultFileSize); } { [self.responseData appendData:data]; NSLog(@"resourceData length: %d", [resourceLength intValue]); NSLog(@"filesize: %d", self.searchResultFileSize); NSLog(@"float filesize: %f", [self.searchResultFileSize floatValue]); HUD.progress = [resourceLength floatValue] / [self.searchResultFileSize floatValue]; NSLog(@"progress: %f", [resourceLength floatValue] / [self.searchResultFileSize floatValue]); } { [self setSearchingModeEnabled:NO]; initWithFormat:@"Connection failed: %@", [error description]]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" message:detailMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; [detailMessage release]; } { [self setSearchingModeEnabled:NO]; [connection release]; [self.responseData release]; //parse the result and remove outermost wrapper SBJSON *parser = [[SBJSON alloc] init]; //evaluate the results, and keep only unique ones if (![[searchResultsKeepers allKeys] containsObject:[entry objectForKey:@"label"]]) { //insert the search type [modifiedEntry setObject:searchType forKey:@"type"]; [searchResultsKeepers setObject:modifiedEntry forKey:[modifiedEntry objectForKey:@"label"]]; [modifiedEntry release]; } } self.searchResults = searchResultsKeepers; [searchResultsKeepers release]; [parser release]; [jsonResponse release]; [resultsView reloadData]; }
以上是关于带有异步NSURLConnection调用的MBProgressHUD的主要内容,如果未能解决你的问题,请参考以下文章
使用来自异步 NSURLConnection 的数据填充 NSImage