【发布时间】:2018-03-03 20:37:45
【问题描述】:
我是初学者,我从服务器获取 300 个数据并将这些数据存储在一个数组 [[String:String]] 中,我不希望所有这 300 个数据一次显示在表格视图中,但是我想要以增量方式显示它,假设在表格视图中每次滚动 15 个数据,加载 15 个数据后,如果用户到达表格视图滚动的底部,将加载下一个 15 个数据。
我应该这样做,因为其中一个数据实际上是一个 imagePath,所以我将下载一个图像,如果我一次下载所有 300 个图像会花费太多时间。
我已经尝试过,但我无法得到我想要的。我将这种情况简化为仅使用整数数组,如下面的代码。你能帮我怎么做吗?在此先感谢:)
class ViewController2: UIViewController {
@IBOutlet weak var tableView: UITableView!
var data = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
for i in 0...300 {
data.append(i)
}
}
}
extension ViewController2 : UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: nil)
cell.textLabel?.text = "\(data[indexPath.row])"
return cell
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
}
}
【问题讨论】:
-
您可以加载部分数据(逐步)并加载每个部分的内容
标签: ios swift uitableview pagination