【问题标题】:Hyperlink button doesn't respond: iOS超链接按钮没有响应:iOS
【发布时间】:2014-09-27 23:17:49
【问题描述】:

基本上,我在所有可能的地方都彻底寻找了解决方案,似乎在将 URL 链接分配给按钮时我做的一切都是正确的。问题是它根本没有响应。什么都不做。

代码:

- (IBAction)firstViewBackButton:(id)sender {

    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)red:(id)sender {

    [[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"www.google.com"]];
}

红色按钮位于 .h 和 .m 文件中。 red 与代码相关联。

我阅读了一个修复程序,似乎我应该去 File>Restore...smthing 并且它以某种方式在模拟器中启用了 Safari。但我在模拟器文件部分没有这样的选项。

非常感谢您的帮助!

【问题讨论】:

    标签: ios objective-c xcode url hyperlink


    【解决方案1】:

    试试这个 替换

    [NSURL URLWithString:@"www.google.com"]];
    

    [NSURL URLWithString:[@"http://www.google.com"  stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    

    【讨论】:

      【解决方案2】:

      使用

      -canOpenURL:
      

      它是一个给出 BOOL 结果的函数。

      答案是

      - (IBAction)red:(id)sender {
          if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"http://www.google.com"]]){
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
          }
      }
      

      如果应用程序可以打开它打开的 url

      【讨论】:

        猜你喜欢
        • 2019-09-01
        • 2017-03-29
        • 1970-01-01
        • 1970-01-01
        • 2022-07-22
        • 1970-01-01
        • 2019-06-24
        相关资源
        最近更新 更多