成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

IOS開發(fā)應(yīng)用中NSDATA轉(zhuǎn)換為NSSTRING時亂碼問題解決

移動開發(fā) iOS
IOS開發(fā)應(yīng)用中NSDATA轉(zhuǎn)換為NSSTRING時亂碼問題解決是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)亂碼的解決問題,本文通過NSDATA和NSSTRING來實現(xiàn)亂碼的解決。

IOS開發(fā)應(yīng)用中NSDATA轉(zhuǎn)換為NSSTRING亂碼問題解決是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)亂碼的解決問題,本文通過NSDATANSSTRING來實現(xiàn)亂碼的解決。讀取HTML內(nèi)容后,返回的 NSDATA 轉(zhuǎn)換為 NSSTRING 時經(jīng)常出現(xiàn)亂碼。來看詳細(xì)內(nèi)容講解。

  1. //  
  2. //  WeatherFetcherAppDelegate.h  
  3. //  WeatherFetcher  
  4. //  
  5. //  Created by  cy on 10-8-9.  
  6. //  Copyright CY.COM 2010. All rights reserved.  
  7. //  
  8. #import <UIKit/UIKit.h> 
  9.  
  10. @interface WeatherFetcherAppDelegate : NSObject <UIApplicationDelegate,UISearchBarDelegate> {  
  11. UIWindow *window;  
  12. IBOutlet UIWebView *wv;  
  13. IBOutlet UISearchBar *sb;  
  14. IBOutlet UIActivityIndicatorView *ai;  
  15. NSMutableData *receivedData;  
  16. NSMutableData *data1;  
  17. NSMutableArray *elements;  
  18. NSString *element;  
  19. }  
  20.  
  21. @property (nonatomic, retain) IBOutlet UIWindow *window;  
  22. @property (nonatomic, retain) IBOutlet UIWebView *wv;  
  23.  
  24. @end  
  25.  
  26. //  
  27. //  WeatherFetcherAppDelegate.m  
  28. //  WeatherFetcher  
  29. //  
  30. //  Created by  cy on 10-8-9.  
  31. //  Copyright CY.COM 2010. All rights reserved.  
  32. //  
  33.  
  34. #import "WeatherFetcherAppDelegate.h"  
  35.  
  36. @implementation WeatherFetcherAppDelegate  
  37.  
  38. @synthesize window;  
  39. @synthesize wv;  
  40.  
  41. #pragma mark -  
  42. #pragma mark Application lifecycle  
  43.  
  44. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {      
  45.  
  46. // Override point for customization after application launch.  
  47.  
  48.     [window makeKeyAndVisible];  
  49. [ai setHidden:YES];  
  50. return YES;  
  51. }  
  52.  
  53. - (void)applicationWillResignActive:(UIApplication *)application {  
  54.     /*  
  55.      Sent when the application is about to move from active to inactive state. 
  56. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) 
  57. or when the user quits the application and it begins the transition to the background state.  
  58.      Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. 
  59. Games should use this method to pause the game.  
  60.      */  
  61. }  
  62.  
  63. - (void)applicationDidEnterBackground:(UIApplication *)application {  
  64.     /*  
  65.      Use this method to release shared resources, save user data, invalidate timers, 
  66. and store enough application state information to restore your application to its current state in case it is terminated later.   
  67.      If your application supports background execution, called instead of applicationWillTerminate: when the user quits.  
  68.      */  
  69. }  
  70.  
  71. - (void)applicationWillEnterForeground:(UIApplication *)application {  
  72.     /*  
  73.      Called as part of  transition from the background to the inactive state: here you can undo many of the changes 
  74. made on entering the background.  
  75.      */  
  76. }  
  77.  
  78. - (void)applicationDidBecomeActive:(UIApplication *)application {  
  79.     /*  
  80.      Restart any tasks that were paused (or not yet started) while the application was inactive. 
  81. If the application was previously in the background, optionally refresh the user interface.  
  82.      */  
  83. }  
  84.  
  85. - (void)applicationWillTerminate:(UIApplication *)application {  
  86.     /*  
  87.      Called when the application is about to terminate.  
  88.      See also applicationDidEnterBackground:.  
  89.      */  
  90. }  
  91.  
  92. #pragma mark -  
  93. #pragma mark Memory management  
  94.  
  95.  
  96. - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {  
  97.     /*  
  98.      Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.  
  99.      */  
  100. }  
  101.  
  102. - (void)dealloc {  
  103.     [window release];  
  104.     [super dealloc];  
  105. }  
  106.  
  107. -(void) searchBarSearchButtonClicked:(UISearchBar *)searchBar{  
  108.  
  109. [sb resignFirstResponder];  
  110. [ai setHidden:NO];  
  111. [ai startAnimating];  
  112. // create the request     
  113. NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL   
  114.     URLWithString:@"http://wap.sohu.com/"]     
  115.   cachePolicy:NSURLRequestUseProtocolCachePolicy   
  116.   timeoutInterval:60.0];    
  117.  
  118. // create the connection with the request     
  119. // and start loading the data     
  120. NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest     
  121.     delegate:self];     
  122.  
  123. if (theConnection) {     
  124. // Create the NSMutableData that will hold     
  125. // the received data     
  126. // receivedData is declared as a method instance elsewhere     
  127. receivedData=[[NSMutableData data] retain];     
  128. } else {     
  129. // inform the user that the download could not be made     
  130. }     
  131. [ai stopAnimating];  
  132.  
  133. }  
  134. - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response     
  135. {     
  136. // this method is called when the server has determined that it     
  137. // has enough information to create the NSURLResponse     
  138. // it can be called multiple times, for example in the case of a     
  139. // redirect, so each time we reset the data.     
  140. // receivedData is declared as a method instance elsewhere     
  141.     [receivedData setLength:0];     
  142. }     
  143.  
  144. - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data     
  145. {     
  146. // append the new data to the receivedData     
  147. // receivedData is declared as a method instance elsewhere     
  148.     [receivedData appendData:data];     
  149. }     
  150. - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error     
  151. {     
  152. // release the connection, and the data object     
  153. [connection release];     
  154. // receivedData is declared as a method instance elsewhere     
  155.     [receivedData release];     
  156.  
  157. }     
  158.  
  159. - (void)connectionDidFinishLoading:(NSURLConnection *)connection     
  160. {     
  161.  
  162. NSStringEncoding strEncode = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);  
  163.     NSString *strReceive = [[NSString alloc] initWithData:receivedData encoding:strEncode];  
  164.  
  165.     [wv loadHTMLString:strReceive baseURL:nil];  
  166.  
  167. // release the connection, and the data object     
  168.     [connection release];     
  169.     [receivedData release];     
  170. }     
  171. @end 

小結(jié):IOS開發(fā)應(yīng)用中NSDATA轉(zhuǎn)換為NSSTRING亂碼問題解決的內(nèi)容介紹完了想,希望通過本文的學(xué)習(xí)能對你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2009-06-19 11:16:14

java web中文亂碼

2009-06-30 14:02:00

Struts亂碼Eclipse

2014-04-21 15:59:59

iOS 7.1企業(yè)應(yīng)用證書無效

2013-06-14 10:48:53

IIS 7

2009-03-06 10:10:00

廣播風(fēng)暴網(wǎng)絡(luò)

2010-04-13 14:25:24

Oracle問題解決

2011-02-23 13:48:05

Web

2011-04-25 13:06:38

EclipseLinux

2011-06-14 13:41:27

muleWSDL

2011-06-27 16:44:59

Qmake

2011-06-13 16:16:32

Qt 中文問題

2010-04-28 18:01:15

Unix系統(tǒng)

2010-06-17 11:35:24

Ubuntu 修復(fù)Gr

2010-01-05 10:02:56

LinuxRAID常見問題

2010-04-28 19:24:17

Hp unix

2010-08-04 10:20:30

Flex組件開發(fā)

2010-05-05 10:25:24

Unix操作系統(tǒng)

2011-11-28 22:45:19

Nginxsession

2009-12-28 10:56:45

WPF Image

2010-09-07 09:08:03

DIV彈出層
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 国产成人精品一区二区三区网站观看 | 无码日韩精品一区二区免费 | 欧美一级黄 | 欧美精品一二三区 | 欧美一区不卡 | 欧美国产精品一区二区三区 | 污片在线免费观看 | 午夜影晥| 国产精品区二区三区日本 | 综合九九 | 婷婷在线免费 | 国产激情在线 | 亚洲 91| 欧美性受 | 国产专区在线 | 成人在线视频网站 | 久草视频在线看 | 久久99精品久久久水蜜桃 | 免费激情网站 | 91资源在线 | 国产精品成人一区二区三区 | 日本天天操 | 日韩成人免费视频 | 91丨国产| 一区二区国产精品 | 亚洲欧美在线视频 | 亚洲欧美国产精品一区二区 | 国产在线精品一区二区 | 久久夜视频 | 国产电影精品久久 | 久久久.com| 精品在线一区 | 久久高清 | www.久久久.com | 亚洲网站在线观看 | 国产综合一区二区 | 一区二区三区av | 老子午夜影院 | 国产精品一区二区三区在线 | 亚洲成人av一区二区 | 奇米av |