我是 Xcode 和编程语言的新手,我需要你的帮助。我正在处理消息应用程序,但无法使用完成处理程序块。这是我的代码:
@IBAction func SendButton(_ sender: AnyObject) {
if self.textfield.text != "" {
let mess = CKRecord(recordType: "Message")
mess["content"] = textfield.text as CKRecordValue?
let publicdata = CKContainer.default().publicCloudDatabase
publicdata.save(mess, completionHandler: {(record, error) -> Void in
if error == nil {
let indexpath = NSIndexPath(item: self.chat.count, section: 0)
CATransaction.begin()
CATransaction.setDisableActions(true)
self.CollView.performBatchUpdates ({
self.chat.insert(mess, at: self.chat.count)
self.CollView.insertItems(at: [indexpath as IndexPath])
}, completion: {(true) -> Void in
print("Animation completed")
self.CollView.contentOffset = CGPoint(x: 0, y: 40)
})
CATransaction.commit()
print("SAVED")
}else{
print("error")
}})
}
textfield.text = ""
}
我使用CATransaaction 执行BatchUpdates,但是performBatchUpdates 方法中的Completion Handler Block 无法完成。如您所见,这不是正确的编写方式,我知道,但是我已经尝试了所有我知道的方法来实现它,但它不会。完成 :
completion: {(true) -> Void in
print("Animation completed")
self.CollView.contentOffset = CGPoint(x: 0, y: 40)
})
请帮我。谢谢 !!