Iphone 设置一个UIButton来调用某个数字Xcode

Iphone 设置一个UIButton来调用某个数字Xcode,iphone,xcode,Iphone,Xcode,我有一个带有4个UIButton的应用程序,我想为每个按钮预先设置电话号码。我是这样写的: - (IBAction)callFirst:(id)sender { [NSURL URLWithString:@"tel.0739421700"]; } - (IBAction)callSecond:(id)sender { [NSURL URLWithString:@"tel.0705652000"]; } - (IBAction)callThird:(id)sender { [NSURL URL

我有一个带有4个UIButton的应用程序,我想为每个按钮预先设置电话号码。我是这样写的:

- (IBAction)callFirst:(id)sender {
[NSURL URLWithString:@"tel.0739421700"];
}

- (IBAction)callSecond:(id)sender {
[NSURL URLWithString:@"tel.0705652000"];
}

- (IBAction)callThird:(id)sender {
[NSURL URLWithString:@"tel.0705666900"];
}

- (IBAction)callFourth:(id)sender {
[NSURL URLWithString:@"tel.0702857900"];
}
当我在模拟器上打开应用程序时,它会将我带到日志并显示错误。我该怎么写呢? 这就是我运行它时出现的问题。“return UIApplicationMain…”零件的边缘标有绿色箭头。右边写着“thread1:sigabrt”,它来自main.m文件:

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
#导入
#导入“AppDelegate.h”
int main(int argc,char*argv[])
{
@自动释放池{
返回UIApplicationMain(argc、argv、nil、NSStringFromClass([AppDelegate类]);
}
}
提前谢谢

  • 你没有
  • 你用错了
  • 像这样的方法应该会奏效:

    - (BOOL)callPhoneNumberWithString:(NSString *)phoneNumberString {
        NSURL *url = [NSURL URLWithString:phoneNumberString];
        if ([[UIApplication sharedApplication] canOpenURL:url]) {
            [[UIApplication sharedApplication] openURL:url];
            return YES;
        }
        return NO;
    }
    
    - (IBAction)callFirst:(id)sender {
        [self callPhoneNumberWithString:@"tel:0123456789"]; 
    }
    

    您的代码错误,但不会崩溃。检查您的xib或故事板中的连接是否如Matthias Bauch所说,我必须调用URL?按钮未连接,但无论如何都无法工作:(它显示的内容与以前相同:(但我应该如何在其他操作中重复此操作?