偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

iPhone開發(fā)應(yīng)用幾個(gè)案例實(shí)現(xiàn)分析

移動(dòng)開發(fā) iOS
iPhone開發(fā)應(yīng)用幾個(gè)案例實(shí)現(xiàn)分析是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)對(duì)iphone開發(fā)中幾個(gè)小案例的實(shí)現(xiàn)進(jìn)行來講解并分析,具體內(nèi)容來看本文詳解。

iPhone開發(fā)應(yīng)用幾個(gè)案例實(shí)現(xiàn)分析是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)對(duì)iphone開發(fā)中幾個(gè)小案例的實(shí)現(xiàn)進(jìn)行來講解并分析,具體內(nèi)容來看本文詳解。

1、解析NSString形式xml的代碼 

提出的問題:

  1. NSString *xmlString = @"<person><name>Jack</name><age>13< /age></person>"; 

如何對(duì)這個(gè)xmlString構(gòu)造一個(gè)NSXML,以及如何解析構(gòu)造的NSXML.

解決方法:先轉(zhuǎn)換成NSData,然后用NSXMlParser進(jìn)行解析。代碼:

  1. - (void)handleXMLData {       
  2.     NSString *myString = @"<addresses owner='swilson'><person><lastName>Doe</lastName><firstName>John</firstName></person></addresses>";   
  3.     NSData *myRequestData = [ NSData dataWithBytes: [myString UTF8String]  length:[myString length]];     
  4.     NSXMLParser *myParser = [[NSXMLParser alloc] initWithData:myRequestData];   
  5.     [myParser setDelegate:self];   
  6.     [myParser setShouldProcessNamespaces:YES];   
  7.     [myParser setShouldReportNamespacePrefixes:YES];   
  8.     [myParser setShouldResolveExternalEntities:NO];   
  9.     BOOL success = [myParser parse];   
  10.     [myParser release];  

2、iphone開發(fā)中讓用戶WebView訪問網(wǎng)頁時(shí)嵌入開發(fā)者自己的內(nèi)容
 
代碼

  1. NSString *strUrl=[textField text];  
  2.   NSString *urlString=[NSString stringWithFormat:strUrl];  
  3.   NSURL *url=[NSURL URLWithString:urlString];  
  4.   NSURLRequest *urlRequest=[NSURLRequest requestWithURL:url  
  5.                                             cachePolicy:NSURLRequestReturnCacheDataElseLoad  
  6.                                         timeoutInterval:60];  
  7.   NSData *urlData;  
  8.   NSURLResponse *response;  
  9.   NSError *error;  
  10.   urlData=[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];  
  11.   NSString *dataStr =[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];  
  12.   dataStr = [dataStr substringToIndex:[dataStr length] - 16];  
  13.   dataStr = [dataStr stringByAppendingString:@"<p>hello world navy did it </p></body></html>"];  
  14.   NSLog(@"%@",dataStr);  
  15.   const char *cString = [dataStr UTF8String];  
  16.   NSData *myData= [[NSData alloc]initWithBytes:cString length:strlen(cString)+1];  
  17.   [self.myWebView loadData:myData MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:url]; 

這個(gè)代碼我是在UICatalog中WebViewController中添加的,有人要這功能,小生就乘機(jī)學(xué)習(xí)了下,嫌麻煩,直接用的UICatalog代碼.見諒.

此代碼功能在于:在你訪問的網(wǎng)頁左下角加了hello world navy did it.幾個(gè)字.

不希望做流氓功能.一切以用戶為主.

3、iPhone開發(fā)中,動(dòng)態(tài)調(diào)用類和方法

舉一個(gè)很簡單的例子:

某公司的有1000名員工, 每個(gè)員工的工資都不一樣. 發(fā)工資的時(shí)候, 這要是人工去發(fā), 耗費(fèi)的時(shí)間和精力是非常大的. 所以財(cái)務(wù)會(huì)打一個(gè)表格給銀行, 委托銀行轉(zhuǎn)賬.

站在銀行的角度, 如果有1000個(gè)公司, 委托銀行轉(zhuǎn)賬發(fā)工資. 它應(yīng)該怎么做呢? 它需要通過電子轉(zhuǎn)賬系統(tǒng), 輸入公司名字, 每個(gè)員工的工資數(shù), 就可以實(shí)現(xiàn)自動(dòng)轉(zhuǎn)賬了.

好, 我們回到 iPhone 開發(fā)上來:

我們現(xiàn)在面臨的情況是, 有10個(gè)類, 每個(gè)類里頭都有n個(gè)方法(前提是方法名有規(guī)律可循,比如 setA0,setA1…) 如果挨個(gè)去init類, 然后挨個(gè)調(diào)用方法,這樣你一天就不用干別的了.

Objective-C里 面,我們可以這樣實(shí)現(xiàn):

有數(shù)組: classNames, 存著 類的名字

方法名都是 setA 開頭

  1. for (int c=0; c<[classNames count]; c++) {  
  2. NSString *className=[classNames objectAtIndex:c];  
  3. id class=[[NSClassFromString(className) alloc] init];  
  4. for (int i=0; i<[params count]; i++) {  
  5. [class performSelector:NSSelectorFromString([NSString stringWithFormat:@"setA%i",i])];  
  6. }  

兩個(gè)重要的宏 我加大字體標(biāo)出來了,然后你可以再發(fā)揮一下, 比如傳參數(shù)。

4、iPhone開發(fā)項(xiàng)目中加載本地html文件到uiwebview的代碼

如果您想在iPhone項(xiàng)目中加載Documents里面的文件,可以嘗試CocoaChina版主“lvyile”提供的代碼

  1. - (void)loadDocument:(NSString*)docName {   
  2.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  3.     NSString *documentsDirectory = [paths objectAtIndex:0];      
  4.     NSString *path = [documentsDirectory stringByAppendingPathComponent:docName];      
  5.     NSURL *url = [NSURL fileURLWithPath:path];  
  6.     NSURLRequest *request = [NSURLRequest requestWithURL:url];  
  7.    
  8.     self.myWebView.scalesPageToFit = YES;  
  9.    
  10.     [self.myWebView loadRequest:request];  

如果加載App內(nèi)部的文件,需要改一下代碼

  1. NSString   
  2. *mainBundleDirectory = [[NSBundle mainBundle] bundlePath];  
  3. NSString   
  4. *path = [mainBundleDirectory  stringByAppendingPathComponent:docName]; 

小結(jié):iPhone開發(fā)應(yīng)用幾個(gè)案例實(shí)現(xiàn)分析的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對(duì)你有所幫助!更多關(guān)于iphone開發(fā)的相關(guān)的內(nèi)容,請(qǐng)參考iphone開發(fā)頻道的內(nèi)容。

責(zé)任編輯:zhaolei 來源: CocoaChina
相關(guān)推薦

2011-08-15 15:44:46

iPhone開發(fā)PDF

2011-08-18 16:24:44

iPhone開發(fā)圖片

2011-08-16 15:48:37

iPhone開發(fā)抓圖程序

2011-08-19 11:10:31

iPhone應(yīng)用

2011-08-18 15:24:40

iPhone國際化

2011-08-19 10:05:30

iPhone開發(fā)

2011-08-17 16:12:20

iPhone應(yīng)用程序

2011-08-15 18:02:32

iPhone開發(fā)表視圖

2011-08-15 10:06:22

iPhone開發(fā)nib 文件

2011-08-16 15:36:47

iPhone應(yīng)用測試

2011-08-17 16:23:31

iPhone開發(fā)UIViewContr

2012-05-09 09:49:57

移動(dòng)支付

2011-07-25 17:07:16

iPhone KVO KVC

2011-08-19 10:01:09

iPhone應(yīng)用SqliteUITableView

2011-08-18 16:42:07

iPhone應(yīng)用APNS推送

2011-08-12 11:31:46

iPhoneUIView動(dòng)畫

2011-07-25 14:44:41

iPhone iPhone開發(fā) 截屏

2011-08-15 13:50:06

IPhone開發(fā)UIView動(dòng)畫

2011-08-05 13:49:53

iPhone 應(yīng)用 開發(fā)

2011-08-17 16:29:12

iPhone開發(fā)UIButton
點(diǎn)贊
收藏

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