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

IOS開發應用中NSDATA轉換為NSSTRING時亂碼問題解決

移動開發 iOS
IOS開發應用中NSDATA轉換為NSSTRING時亂碼問題解決是本文要介紹的內容,主要是來學習亂碼的解決問題,本文通過NSDATA和NSSTRING來實現亂碼的解決。

IOS開發應用中NSDATA轉換為NSSTRING亂碼問題解決是本文要介紹的內容,主要是來學習亂碼的解決問題,本文通過NSDATANSSTRING來實現亂碼的解決。讀取HTML內容后,返回的 NSDATA 轉換為 NSSTRING 時經常出現亂碼。來看詳細內容講解。

  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 

小結:IOS開發應用中NSDATA轉換為NSSTRING亂碼問題解決的內容介紹完了想,希望通過本文的學習能對你有所幫助!

責任編輯:zhaolei 來源: 互聯網
相關推薦

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企業應用證書無效

2009-03-06 10:10:00

廣播風暴網絡

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

2013-06-14 10:48:53

IIS 7

2010-04-28 18:01:15

Unix系統

2010-06-17 11:35:24

Ubuntu 修復Gr

2011-06-27 16:44:59

Qmake

2011-06-13 16:16:32

Qt 中文問題

2010-04-28 19:24:17

Hp unix

2010-01-05 10:02:56

LinuxRAID常見問題

2010-08-04 10:20:30

Flex組件開發

2010-05-05 14:20:46

AIX CDE

2012-05-09 10:08:41

跨機房

2011-01-21 14:13:10

2010-05-05 10:25:24

Unix操作系統
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 欧美日韩亚洲国产综合 | 97中文视频| 国产目拍亚洲精品99久久精品 | 久久免费精品 | 男人久久天堂 | 91精品国产高清一区二区三区 | 精品一区二区在线观看 | 99精品国产一区二区青青牛奶 | 久草欧美视频 | 国产女人叫床高潮大片免费 | 成人黄色av网站 | 日韩国产黄色片 | 欧美a级网站 | 亚洲午夜一区二区 | 日韩视频在线播放 | 亚洲黄色在线 | 久久日韩精品 | 亚洲一区av在线 | 做a的各种视频 | 一区二区三区四区电影视频在线观看 | 99riav3国产精品视频 | 亚洲精品久久久一区二区三区 | 一区精品在线观看 | 国产一区二区三区网站 | 91社区在线观看 | 看特级黄色片 | 亚洲人成人一区二区在线观看 | 91亚洲国产成人久久精品网站 | 九九视频在线观看 | 久久久九九 | 国产亚洲精品a | 毛片免费视频 | 免费欧美视频 | 国产精品久久久久9999鸭 | 日韩欧美一级 | 五月婷婷导航 | 中文字幕亚洲区一区二 | 精品视频一区二区三区在线观看 | 免费超碰 | 中文字幕在线视频精品 | 久久久青草婷婷精品综合日韩 |