简体   繁体   中英

iPhone NSURL error

I'm using this code to assign the link of my button to the wiki page, while capturing the countryName.text in the UILabel to be a part of the URL, but Xcode gives me an error when I press it. Here's the code:

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

Thanks in advance.

In your format you expect two parameters, but give only one:

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

Remove one specifier:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM