A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 红凉梦 中级黑马   /  2016-1-21 12:44  /  713 人查看  /  3 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

1:NSURL初始化方法:
[csharp] view plaincopy
NSURL *url=[NSURL URLWithString:@"http://www.baidu.com?id=1"];  

2:解决NSURL初始化失败的方法.
将传进来的NSString 进行 UTF8 转码即可.
[csharp] view plaincopy
NSString *strLocalHtml = @"file:///Users/amarishuyi/Desktop/My IPhone Life/WebDeveloper/WebPlug-in/ExtEditor/DataPage/KMQT/Ext-HTMLEditor.html";  
strLocalHtml = [NSString stringWithFormat:@"%@?Value=%@",strLocalHtml,self.txtUrl.text];  
strLocalHtml= [strLocalHtml stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  
NSURL * url=[NSURL URLWithString:strLocalHtml];  

3:NSURL 成功初始化后可以获取的参数 (摘自:NSURL 学习 )

[csharp] view plaincopy
NSURL *url = [NSURL URLWithString:  @"http://www.baidu.com/s?tn=baiduhome_pg&bs=NSRUL&f=8&rsv_bp=1&rsv_spt=1&wd=NSurl&inputT=2709"];     
NSLog(@"Scheme: %@", [url scheme]);   
NSLog(@"Host: %@", [url host]);   
NSLog(@"Port: %@", [url port]);        
NSLog(@"Path: %@", [url path]);        
NSLog(@"Relative path: %@", [url relativePath]);   
NSLog(@"Path components as array: %@", [url pathComponents]);           
NSLog(@"Parameter string: %@", [url parameterString]);      
NSLog(@"Query: %@", [url query]);         
NSLog(@"Fragment: %@", [url fragment]);  
NSLog(@"User: %@", [url user]);  
NSLog(@"Password: %@", [url password]);  
结果如下:
[csharp] view plaincopy
2012-03-31 18:22:20.904 SmallDemoList[5473:11603] 12131232  
2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Scheme: http  
2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Host: www.baidu.com  
2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Port: (null)  
2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Path: /s  
2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Relative path: /s  
2012-03-31 18:22:20.907 SmallDemoList[5473:11603] Path components as array: (  
    "/",  
    s  
)  
2012-03-31 18:22:20.916 SmallDemoList[5473:11603] Parameter string: (null)  
2012-03-31 18:22:20.917 SmallDemoList[5473:11603] Query: tn=baiduhome_pg&bs=NSRUL&f=8&rsv_bp=1&rsv_spt=1&wd=NSurl&inputT=2709  
2012-03-31 18:22:20.917 SmallDemoList[5473:11603] Fragment: (null)  
2012-03-31 18:22:20.917 SmallDemoList[5473:11603] User: (null)  
2012-03-31 18:22:20.917 SmallDemoList[5473:11603] Password: (null)  

4:根据文件名称和文件后缀获取程序包内容文件的路径
NSURL *urlKindEditor = [[NSBundlemainBundle] URLForResource:@"simple"withExtension:@"html"subdirectory:@"KindEditor/examples"];

URLForResource:文件名称
withExtension:文件后缀
subdirectory:在程序包中的哪个子目录中寻找.
如果没有找到将会返回nil
找到后返回如下路径: file://localhost/Users/amarishuyi/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/FB0CDABC-D0E2-45FF-AA2C-959E8A65ADB4/SmallDemoList.app/KindEditor/examples/simple.html

3 个回复

倒序浏览
我来水一水
回复 使用道具 举报
学习了~~~~~~~~赞赞哒
回复 使用道具 举报
url是什么.......
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马