简体   繁体   中英

Refresh TableView except pull to refresh

I use Parse to save data and every time I add new data to server,TableView doesn't refresh and get new data

Is any way to refresh TableView except pull refresh ?

First of all Add Observer method which will notify when you.

NotificationCenter.default.post(name: Notification.Name("ReloadTableData"), object: nil)

Register that observer method in your view controller on which tableview you used.

 NotificationCenter.default.addObserver(self, selector: #selector(self.methodOfReceivedNotification(notification:)), name: Notification.Name("ReloadTableData"), object: nil)

and create one function and reload your tableview

This might by your possible solutions for reloading without pull to refresh.

You can use this:

self.tableView.reloadData()

Whenever the user get back to the app or opens the app. You can add in in the method

applicationWillEnterForeground

If the user is still in the app while the updates are being performed, then use push notification. In the method

appDidReceiveRemoteNotification 

reload the data. You have to register for remote notification and all the process before you receive any push notification, but that is another issue.

first of all Adding refresh control to the tableview. So add the below code in ViewDidLoad .

    let refresh = UIRefreshControl()
    refresh.tintColor = UIColor.redColor()
    refresh.attributedTitle = NSAttributedString(string:"Loading..!!", attributes: [NSForegroundColorAttributeName: UIColor.redColor()])
    refresh.addTarget(self, action: "handleRefresh:", forControlEvents: UIControlEvents.ValueChanged)
    self.tableView.addSubview(refresh)
    self.tableView.sendSubviewToBack(refresh)

Now Calling the method when you Pull-To-refresh Tableview.

func handleRefresh(refreshControl : UIRefreshControl){
    self.tableView.reloadData()
    refreshControl.endRefreshing()
}

Refresh Control :

在此处输入图片说明

Implement a push notification or use LiveQuery on parse-server .

LiveQuery allows you to subscribe to a Parse.Query you are interested in. Once subscribed, the server will notify clients whenever a Parse.Object that matches the Parse.Query is created or updated, in real-time.

LiveQuery is already support IOS .

for more detail see the hyperLink.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM