2011-06-27 16 views
1

私は基本的なRSSリーダーを作っています。Safariでリンクを開く必要がありますが、セルをクリックすると何も起こりません。ここで私が持っているものである:ここではSafariを開いていないリンク

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
//Navigation Logic: 

int storyIndex = [indexPath indexAtPosition: [indexPath length] -1]; 
NSString *storyLink = [[stories objectAtIndex: storyIndex] objectForKey:@"link"]; 

//cleaning up the link... 

storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""]; 
storyLink = [storyLink stringByReplacingOccurrencesOfString:@"/n" withString:@""]; 
storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""]; 

NSLog(@"link: %@", storyLink); 

//open in Safari 
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]]; 


} 

は、コンソールログです:

2011-06-27 20:03:51.817 ParadiseBeats[26927:207] all done 
2011-06-27 20:03:51.818 ParadiseBeats[26927:207] stories array had 20 items 
2011-06-27 20:03:53.758 ParadiseBeats[26927:207] link: technobuffalo.com/companies/apple/… 

そして、私がリンクに置く:

- (void)viewDidAppear:(BOOL)animated 
{ 
    [super viewDidAppear:animated]; 
if ([stories count] == 0) { 
    NSString *path = @"http://www.technobuffalo.com/feed/"; 
    [self parseXMLFileAtURL:path]; 
} 

}

ここでは解析がありますコード:

-(void)parser:(NSXMLParser *) parser didStartElement:(NSString *) elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *__strong)qName attributes:(NSDictionary *__strong)attributeDict { 

currentElement = [elementName copy]; 
if([elementName isEqualToString:@"item"]){ 
    //clear out story item caches... 
    item = [[NSMutableDictionary alloc] init]; 
    currentTitle = [[NSMutableString alloc] init]; 
    currentDate = [[NSMutableString alloc] init]; 
    currentSummary = [[NSMutableString alloc] init]; 
    currentLink = [[NSMutableString alloc] init]; 

} 

} 

    -(void)parser:(NSXMLParser *)parser didEndElement:(NSString *__strong)elementName namespaceURI:(NSString *__strong)namespaceURI qualifiedName:(NSString *__strong)qName { 

if ([elementName isEqualToString:@"item"]) { 
    [item setObject:currentTitle forKey:@"title"]; 
    [item setObject:currentLink forKey:@"link"]; 
    [item setObject:currentSummary forKey:@"summary"]; 
    [item setObject:currentDate forKey:@"date"]; 

    [stories addObject:[item copy]]; 
    NSLog(@"adding story: %@", currentTitle); 
} 


} 

-(void)parser:(NSXMLParser *) parser foundCharacters:(NSString *__strong)string{ 
//save the characters for the current item 

if ([currentElement isEqualToString:@"title"]) { 
    [currentTitle appendString:string]; 
} 
else if ([currentElement isEqualToString:@"link"]) { 
    [currentLink appendString:string]; 
} 
else if ([currentElement isEqualToString:@"pubDate"]) { 
    [currentDate appendString:string]; 
} 
else if ([currentElement isEqualToString:@"description"]) { 
    [currentSummary appendString:string]; 
} 


} 
+0

ログに記録されているリンクの例を追加できますか? –

+0

2011-06-27 20:03:51.817 ParadiseBeats [26927:207]すべて完了 2011-06-27 20:03:51.818 ParadiseBeats [26927:207]物語の配列には20個のアイテムがあります 2011-06-27 20:03 :53.758 ParadiseBeats [26927:207]リンク:http://www.technobuffalo.com/companies/apple/lulzsecs-goodbye-gift-leaks-att-doc-indicating-4glte-ipad/ – Chris

+1

リンクでプロトコルが指定されていますか?それが必ずしもHTTPを使用していない場合、ファインダーや他のアプリがSafariの前に忍び寄るかもしれません。 –

答えて

2

Depak:あなたのコードは間違っています。接尾辞ではなく接頭辞http://を確認する必要があります。それは次のようになります。

if (![storyLink hasPrefix:@"http://"]) { 
    NSString* oldLink = storyLink; 
    storyLink = [@"http://" stringByAppendingString:oldLink]; 
} 

クリス:あなたはNSStringの、ローカル変数にして、それをログストアからNSURLを作成するとき。私が正しければ、NSURLの作成は失敗し、現在はNULLを-openURLに渡しています。あなたは正常なNSURL開いてみました:あなたのログに示すように、

[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @"http://www.apple.com"]]; 
+0

を追加しました!私はAppleを開こうとすると動作します残りの時間、私のリンクはnullとして表示されます。私は何をしますか? – Chris

+0

ULを作成する前にNSASCIIで文字列をエンコードしていますが、feeds.feedburner.com/paradisebeatsへのパスを変更するとテーブルが空白になります feedburner(atom)は物事を別別に解析しますか? – Chris

+0

また、サイトのrssフィードへのリンクである「http://www.paradisebeats.com/feeds/posts/default」も試してみましたが、これは役に立ちません。 – Chris

1

あなたのリンクは

technobuffalo.com/companies/apple/...

の代わり

です

http://technobuffalo.com/companies/apple/...

「http://」という接頭辞に注意してください。

URL文字列に「http://」というプレフィックスがありません。

+0

これは、スタックオーバーフローの結果として、http :// – Chris

+1

URLの一部が違法であると思われます。あなたは空白と "\ n"を取り除くので、他の違法な文字や組み合わせが残っているかもしれません。オープンされていないURL全体(もちろんNSLogから)を投稿してください。 – Gilbert

+0

http://feeds.feedburner.com/paradisebeats/ このURLからフィードをダウンロードできるかどうか確認できますか? (ここにはhttp://が追加されていますので、先頭に追加してください) – Chris

関連する問題