I have my json file in the web, and I'm retrieving the data to my app from there. My app is about countries, so when I add a new country in my json file, I want to go to my app and when I pull I want to show all the counties AND THE NEW country I have created in my json file.
I have added the UIRefreshControl() to my app but it doesn´t refresh and also the "loading icon" never goes away. Here ia an image:
the "loading icon" never disappears
How can I do that when I create a new country in my json file (for example: England) I pull the screen in my app, and then I have in my App all the countries + England. And make the "loading icon" disappear when all the countries were loaded in the app.
Please help me with this. Thank you very much!
Here is my UIRefreshControl
code:
import UIKit
class TableController: UITableViewController {
var TableData:Array< String > = Array < String >()
var refresh = UIRefreshControl()
override func viewDidLoad() {
super.viewDidLoad()
get_data_from_url("https://mylink")
refresh.tintColor = UIColor.darkGray
self.tableView.addSubview(refresh)
}
Try the below code:-
import UIKit
class TableController: UITableViewController {
var TableData:Array< String > = Array < String >()
var refresh = UIRefreshControl()
override func viewDidLoad() {
super.viewDidLoad()
refresh.tintColor = UIColor.darkGray
refresh.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
self.tableView.addSubview(refresh)
}
func refresh(sender:AnyObject) {
// Code to refresh table view
get_data_from_url("https://mylink") //Call this on different thread and put the below two lines in completion handler of same thread
DispatchQueue.main.sync {
self.tableView.reloadData()
self.refreshControl?.endRefreshing()
}
}
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.