我正在尝试制作一个聊天应用程序,所以我几乎完成了我的工作。但我不知道如何将我的数据从解析中返回到我的代码中。我试过一次,但它不起作用当输入“query.findObjectsInBackgroundWithBlock {(对象:[AnyObject]!,错误:NSError!)-> Void in”时出现错误,我想知道我将如何修复这个问题。
@IBOutlet var chatTextField: UITextField!
@IBOutlet var DockHight: NSLayoutConstraint!
@IBOutlet var SendButton: UIButton!
@IBOutlet var messageTableview: UITableView!
var messagesArray:[String] = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.messageTableview.delegate = self
self.messageTableview.dataSource = self
self.chatTextField.delegate = self
let tappGesture:UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "tableViewTapped")
self.messageTableview.addGestureRecognizer(tappGesture)
//retrive
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func SendButton(sender: UIButton) {
//send button is stoped
//end edding methode for the text
self.chatTextField.endEditing(true)
self.chatTextField.enabled = false
self.SendButton.enabled = false
//create a PFobject
var message = PFObject(className:"Message")
message["Text"] = "\(chatTextField.text)"
message.saveInBackgroundWithBlock {
(success: Bool, error: NSError?) -> Void in
if (success == true) {
NSLog("The Message has been sent")
} else {
NSLog(error!.description)
}
self.SendButton.enabled = true
self.chatTextField.enabled = true
}
}
func retrieveMessage() {
var query:PFQuery = PFQuery(className: "Message")
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) -> Void in
}
}
func tableViewTapped(){
self.chatTextField.endEditing(true)
}
//textfield deligate methode
func textFieldDidBeginEditing(textField: UITextField) {
self.view.layoutIfNeeded()
UIView.animateWithDuration(0.2, animations: {
self.DockHight.constant = 350
self.view.layoutIfNeeded()
}, completion: nil)
}
func textFieldDidEndEditing(textField: UITextField) {
self.view.layoutIfNeeded()
UIView.animateWithDuration(0.3, animations: {
self.DockHight.constant = 44
self.view.layoutIfNeeded()
}, completion: nil)
}
//makrk tableview delegate methode
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.messageTableview.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
cell.textLabel?.text = self.messagesArray[indexPath.row]
return cell
}
var window: UIWindow?
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return messagesArray.count
}
}