简体   繁体   English

超链接按钮无响应:iOS

[英]Hyperlink button doesn't respond: iOS

Basically I've thoroughly looked everywhere I could for a solution and it seems I do everything right when assigning the URL link to a button. 基本上,我已经尽我所能寻找解决方案,并且在将URL链接分配给按钮时,看来我做对了所有事情。 The problem is it does not respond at all. 问题是它根本不响应。 Just does nothing. 什么也没做。

The code: 编码:

- (IBAction)firstViewBackButton:(id)sender {

    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)red:(id)sender {

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

The button red is in .h and .m files. 红色按钮位于.h和.m文件中。 red is linked with code. 红色与代码链接。

I read a fix where it seemed that I should go to File>Restore...smthing and it somehow enables Safari in the simulator. 我在似乎应该去File> Restore ... smthing的地方阅读了一个修复程序,它以某种方式在模拟器中启用了Safari。 But I do not have such option in the simulator File section. 但是我在模拟器的“文件”部分中没有这样的选项。

I would appreciate the help! 我将不胜感激!

use 采用

-canOpenURL:

it is a function which gives BOOL result. 它是一个给出BOOL结果的函数。

the answer is 答案是

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

if the application can open that url it opens 如果应用程序可以打开该网址,则会打开

Try This Replace 试试这个替换

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

with

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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