【发布时间】:2018-03-19 06:42:22
【问题描述】:
我有一个名为challengeTable 的表格视图。该表包含一个图像、一些文本和一个按钮。这些值是从 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
}
我可以通过调用以下方法重新加载表的数据:
Sec1.removeAll()
challengeTable.reloadData()
目前我正在使用导航控制器。因此,我可以简单地通过来回导航来更新我的表格。然而,我想要做的是,我只想在用户滚动到顶部时重新加载我的表数据。
知道我怎么可能做到这一点吗? 谢谢:)
【问题讨论】:
标签: swift xcode uitableview scrollview