0

このコードを使用してボタンのリンクを wiki ページに割り当て、UILabel の countryName.text を URL の一部としてキャプチャしますが、Xcode を押すとエラーが発生します。コードは次のとおりです。

- (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];}

前もって感謝します。

4

1 に答える 1

3

あなたのフォーマットでは2つのパラメーターが必要ですが、1つだけ指定してください。

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

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

- (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];
}
于 2012-05-05T13:27:13.680 に答える