iPhone NSURL 错误

标签 iphone objective-c ios xcode nsurl

我正在使用这段代码将我的按钮链接分配给 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];}

提前致谢。

最佳答案

在您的格式中,您需要两个参数,但只给出一个:

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

删除一个说明符:

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

关于iPhone NSURL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10462289/

相关文章:

ios - 在 iOS 设备上运行 swift 应用程序时出现 THREAD 1 : EXC_BREAKPOINT (code = EXC_ARM_BREAKPOINT. ..) 错误

iphone - 在 iOS 中获取设备信息?

ios - 如何使用 AFNetwork 刷新或取消服务器调用(GET/POST)?

ios - AFNetworking 使用 PUT 请求上传图片?

ios - WatchKit 或 WatchKit Extension 的自定义类之间的区别?

iphone - 按照教程中的说明调用FBSession.activeSession会导致NSException

ios - Xcode 模拟器卡在 "Launching Simulator"并在 Xcode 项目中卡住加载

ios - 所有 UIView 动画/过渡在一段时间后都变得非动画?

ios - 从 Swift 函数中的异步调用返回数据

iOS - 创建自定义 UILabel 并将它们添加到 UIView