2012-11-16 64 views
0

我有一個可能有鏈接的NSTextView控件。我如何獲得鏈接的完整網址?解析Objective-C中的NSURL

這裏是我迄今爲止

-(BOOL)textView:(NSTextView *)aTextView clickedOnLink:(id)aLink atIndex:(NSUInteger)charIndex 
{ 
    NSURL *htmlURL = [NSURL fileURLWithPathComponents:[aLink pathComponents]]; 
} 

這給了我與文件開頭的URL://本地主機...我如何擺脫URL的那部分?

+1

它可能類似於這[問題](http://stackoverflow.com/questions/3692947/get-parts-of-a-nsurl-in-objective-c-for-iphone) – BabyPanda

回答

0
NSURL* url = [NSURL URLWithString:@"http://localhost/myweb/index.html"]; 
NSString* reducedUrl = [NSString stringWithFormat: 
    @"%@://%@", 
    url.scheme, 
    [url.pathComponents objectAtIndex:1]];