有故障的按钮在按下之前会拨打电话

发布于 2024-11-09 06:45:33 字数 629 浏览 0 评论 0原文

该代码有效,但应用程序正在调用该字符串,而无需按下按钮。一旦我到达应用程序的特定页面,它就会绕过所有内容(其他按钮、地图视图等)并进行调用...

我使用的代码是:

   - (void)loadNo2 {
        UIButton *no2 = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [no2 setTitle:@"2108642700" forState:UIControlStateNormal];
        [no2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [no2 setBackgroundColor:[UIColor blackColor]];
        [no2 setFrame:CGRectMake(84, 260, 152, 31)];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];
        [self addSubview:no2];
    }

它有什么问题???

The code works but the app is calling the string without the press of the button. As soon as I reach the particular page of the app, it is bypassing everything (Other buttons, map views, etc) and makes the call...

The code I'm using is:

   - (void)loadNo2 {
        UIButton *no2 = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        [no2 setTitle:@"2108642700" forState:UIControlStateNormal];
        [no2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [no2 setBackgroundColor:[UIColor blackColor]];
        [no2 setFrame:CGRectMake(84, 260, 152, 31)];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];
        [self addSubview:no2];
    }

What is wrong with it???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

黑凤梨 2024-11-16 06:45:33

此行将打开要拨号的对话框。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];

您没有将其添加为按钮操作 - 您只是调用它。

将该行替换为:

  [no2 addTarget:self 
          action:@selector(onNo2Touch) 
forControlEvents:UIControlEventTouchUpInside];

并添加以下内容:

-(void) onNo2Touch:(id) sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];
}

This line brings up the dialog to dial

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];

You didn't add it as a button action -- you are just calling it.

Replace that line with this:

  [no2 addTarget:self 
          action:@selector(onNo2Touch) 
forControlEvents:UIControlEventTouchUpInside];

And add this:

-(void) onNo2Touch:(id) sender {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];
}
剑心龙吟 2024-11-16 06:45:33

看起来您已经从创建按钮的方法中调用了 openURL。
您应该调用 UIApplication sharedApp... (即

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];

在从操作(映射到按钮)调用的方法内。

Looks like you've called the openURL from the method that creates the button.
You should put the call to UIApplication sharedApp... (i.e.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://1234567890"]];
)
inside the method called from the action (that is mapped to the button) .

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文