В моем коде:Swift: Нажмите на текстовое поле, чтобы начать действие
@IBOutlet weak var textField: UITextField!
@IBAction func textField(sender: AnyObject) {
if textField.text != "" {
let newSweet = CKRecord(recordType: "Chat")
newSweet["content"] = textField.text
textField.delegate = self
let publicData = CKContainer.defaultContainer().publicCloudDatabase
publicData.saveRecord(newSweet, completionHandler: { (record:CKRecord?, error:NSError?) -> Void in
if error == nil {
dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.tableView.beginUpdates()
self.sweets.insert(newSweet, atIndex: 0)
let indexPath = NSIndexPath(forRow: 0, inSection: 0)
self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation:
.Top)
func textFieldShouldReturn(textField: UITextField) -> Bool {
self.textField.resignFirstResponder()
return true
}})
}else{
print(error)
}
})
}
}
Я пытаюсь получить доступ к cloudKit
поэтому, когда вы печатаете что-то в UITextField
Активизирует UITextField
@IBAction
. Что происходит, когда я ввожу текст в UITextField
, ничего не происходит, поэтому мне нужно активировать @IBAction
. у кого-нибудь есть решение?
Вы должны использовать функцию TextFieldDelegate, чтобы сделать это – Khuong