【问题标题】:Get phone number in textfield to make a phone call when pressing a button按下按钮时在文本字段中获取电话号码以拨打电话
【发布时间】:2011-08-08 03:21:34
【问题描述】:

应用程序只是想让用户在文本字段中输入电话号码,然后当点击按钮时,它会拨打该号码。什么是最好的代码?我已经在我的 nib 文件中创建了一个按钮和一个文本字段。

我正在使用 Xcode 4。

【问题讨论】:

    标签: ios button textfield phone-call


    【解决方案1】:
    -(IBAction)numberButtonPressed:(UIButton *)pressedButton
    {
    
        self.phoneNumberLabel.text = [self.phoneNumberLabel.text stringByAppendingString: pressedButton.titleLabel.text];
    
    }
    

    您可以在这里查看 turorial:
    http://mobile.tutsplus.com/tutorials/iphone/design-build-a-1980s-ios-phone-app-making-phone-calls/

    【讨论】:

      【解决方案2】:

      Here 向您展示如何做到这一点。只需让 NSMutableString 电话转到您的文本字段(使用 yourTextField.text

      【讨论】:

      • 谢谢。这是要使用的正确代码吗? NSMUtableString *phone = yourTextField.text;然后这个: NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", phone]]; ?
      • 你不需要把它变成一个 NSMutableString,它可以只是一个 NSString,你甚至不需要它!您可以只使用NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@", yourTextField.text]];,它会起作用(只要确保打开该 URL :))
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-21
      • 2016-05-07
      • 2017-11-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多