我有问题。我需要当按下按钮时,这将自动刷新我的页面,将新内容放入其中。可能在发生这种情况时,我希望按钮能够进行圆形动画。提前谢谢。
class ViewControllerAvvisi: UIViewController, UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate
{
var selfTable: NSMutableArray = NSMutableArray()
@IBOutlet weak var MessageTable: UITableView!
@IBOutlet weak var MessageTextField: UITextField!
@IBOutlet weak var SendMessage: UIButton!
var messagesArray:[String] = [String]()
override func viewDidLoad() {
super.viewDidLoad()
self.MessageTable.delegate = self
self.MessageTable.dataSource = self
self.MessageTable.delegate = self
let tapGesture: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "TableViewTapped")
self.MessageTable.addGestureRecognizer(tapGesture)
func retrieveMessages() {
let query = PFQuery(className: "Message")
query.findObjectsInBackgroundWithBlock {
(remoteObjects: [PFObject]?, error: NSError?) -> Void in
self.messagesArray = [String]()
for messageObject in remoteObjects! {
let messageText: String? = (messageObject as PFObject) ["Text"] as? String
if messageText != nil {
self.messagesArray.append(messageText!)
}
}
self.MessageTable.reloadData()
}
}
retrieveMessages()
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.MessageTable.dequeueReusableCellWithIdentifier("MessageCell")! as UITableViewCell
cell.textLabel?.text = self.messagesArray[indexPath.row]
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return messagesArray.count
}
@IBAction func SendMessage(sender: AnyObject) {
self.MessageTable.endEditing(true)
let NewMessage: PFObject = PFObject (className: "Message")
NewMessage["Text"] = self.MessageTextField.text
self.MessageTextField.enabled = false
self.SendMessage.enabled = false
NewMessage.saveInBackgroundWithBlock { (success:Bool, NSError) -> Void in
if (success == true) {
NSLog("Message successfully saved")
}else{
NSLog("Message didn't save")
}
self.MessageTextField.enabled = true
self.SendMessage.enabled = true
self.MessageTextField.text = ""
}
}
@IBAction func Refresh(sender: AnyObject) {
}
}
答案 0 :(得分:2)
只需使用您创建的功能重新加载新数据即可。将其移到viewDidLoad
函数之外。
使用要重新加载数据的按钮添加IBAction并添加retrieveMessages()。重新加载时,将自动加载新数据。
@IBAction func refreshData(sender: AnyObject) {
retrieveMessages()
}
对于圆圈动画,我建议使用UIActivityIndicatorView。