2012-05-05 8 views
0

このコードを使用してボタンのリンクをwikiページに割り当てていますが、UILabelのcountryName.textをURLの一部として取得していますが、Xcodeを押すとエラーになりますそれ。コードは次のとおりです。iPhone NSURLエラー

- (IBAction)openWiki:(id)sender { 
NSString *sampleUrl = [[NSString alloc] initWithFormat:@"http://en.wikipedia.org/wiki/%@%@",self.countryName.text]; 
NSURL *wikiUrl = [[NSURL alloc] initWithString:sampleUrl]; 
[[UIApplication sharedApplication] openURL:wikiUrl];} 

ありがとうございます。あなたの形式で

+0

あなたはXCODEになっているエラーは何ですか?

@"http://en.wikipedia.org/wiki/%@%@",self.countryName.text // ^^ 

1つの指定子を削除しますか –

+0

%@記号の1つを取り除く。 – danielbeard

答えて

3

あなたは2つのパラメータを期待していますが、一つだけを与える:

- (IBAction)openWiki:(id)sender { 
    NSString *sampleUrl = [[NSString alloc] 
     initWithFormat:@"http://en.wikipedia.org/wiki/%@",self.countryName.text]; 
    //            ^^ 
    NSURL *wikiUrl = [[NSURL alloc] initWithString:sampleUrl]; 
    [[UIApplication sharedApplication] openURL:wikiUrl]; 
} 
+0

これは役に立ちましたが、self.countryName.textが「San Marino」(2つの単語ではなく1つの単語)のようなものだった場合、リンクは開かれませんでした:( –

+0

それは問題ではありません。 – MByD

+0

うーん、何にエンコードするの? –