我正在尝试将 UITextField 内的文本转换为字符串,以便我可以在字符串上使用方法“componentsSeperatedByString(".") 将其转换为数组。但我不断收到 UITextField 的错误没有成员“componentsSeperatedByString”。有什么建议吗?谢谢
import UIKit
import Parse
class ViewController: UIViewController {
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBOutlet weak var username: UITextField!
@IBOutlet weak var password: UITextField!
//Login function. Drag Down keyboard after clicking login
@IBAction func Login(sender: AnyObject) {
username.resignFirstResponder()
password.resignFirstResponder()
var username_array: [String] = username.componentsSeperatedByString(".")
}
}
最佳答案
用户名
是一个UITextField
而不是String
。试试这个:
var username_array: [String] = username.text.componentsSeperatedByString(".")
关于ios - Swift:将 UITextField 输入转换为字符串并在特定字符处分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30904957/