有故障的按钮在按下之前会拨打电话
该代码有效,但应用程序正在调用该字符串,而无需按下按钮。一旦我到达应用程序的特定页面,它就会绕过所有内容(其他按钮、地图视图等)并进行调用...
我使用的代码是:
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此行将打开要拨号的对话框。
您没有将其添加为按钮操作 - 您只是调用它。
将该行替换为:
并添加以下内容:
This line brings up the dialog to dial
You didn't add it as a button action -- you are just calling it.
Replace that line with this:
And add this:
看起来您已经从创建按钮的方法中调用了 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) .