I have a table view called
challengeTable
. This table contains an image, some text and a button. These values are retrieved from the RESTFUL API.
var Sec1 = [[String]]()
public func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?{
return sectionTitles[section]
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
switch section {
case 0 :
return Sec1.count
default:
return Sec2.count
}
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = challengeTable.dequeueReusableCell(withIdentifier: cellID) as! CustomisedCell
cell.selectionStyle = .none
switch indexPath.section {
case 0:
cell.CAChallengeTitle.text = Sec1[indexPath.row][0]
cell.CAChallengeTitle.font = UIFont.boldSystemFont(ofSize: 13)
cell.CAChallengeDescription.text = "Starting Date: \(Sec1[indexPath.row][1]) \n\n Ending Date: \(Sec1[indexPath.row][2])"
cell.CAChallengeDescription.numberOfLines = 3
cell.CAChallengeIMG.image = UIImage(named : "Step" )
cell.CAChallengeButt.tag = indexPath[1]
cell.CAChallengeButt.setTitle("Detsils >", for: .normal)
print("Done with sectoin 0")
default:
cell.CAChallengeTitle.text = Sec2[indexPath.row]
cell.CAChallengeDescription.text = "\(Sec2[indexPath.row]) "
cell.CAChallengeButt.tag = indexPath[1]
cell.CAChallengeButt.setTitle("I am interested >", for: .normal)
print("Done with sectoin 1")
}
return cell
}
I can reload the data of the table by calling the following:
Sec1.removeAll()
challengeTable.reloadData()
Currently I am using the navigation controller. Thus, I can update my table simply by navigating back and forth. What I am trying to do however, is that I want to reload my table data simply when the user scrolls to the top.
Any idea how can I possibly do that? Thanks :)