【发布时间】:2017-09-20 00:59:39
【问题描述】:
我有一个应用程序,它在我的 firebase 数据库上搜索一个节点并从该节点中提取一堆图像 URL,然后在表格视图中显示链接到存储的图像。
问题是它会加载每张图片,可能是数百张图片。我想一次只做这么多,以防止数据过度使用。
理想情况下,当有人滚动到接近尾声时,它会感觉到,然后再上传,比如再上传 10 个。
谢谢,我才刚刚开始,所以有什么帮助。
func loadthumbimages()
{
let ref = Database.database().reference(withPath: "ImageLocations/\(myspoits!)/\(DatesTableViewController.passdata!)")
//observing the data changes
ref.observe(DataEventType.value, with: { (snapshot) in
//if the reference have some values
if snapshot.childrenCount > 0
{
//iterating through all the values
for mydata in snapshot.children.allObjects as! [DataSnapshot]
{
//getting values
let artistObject = mydata.value as? [String: AnyObject]
// This is the data of the node
let fileURL = artistObject?["fileURL"]
let thumbFileUrl = artistObject?["thumbFileUrl"]
let ImageName = artistObject?["ImageName"]
//print(artistObject)
self.myarray1.append("\(ImageName!)")
self.myarray2.append("\(thumbFileUrl!)")
self.myarray3.append("\(fileURL!)")
//print(thumbFileUrl!)
}
}
})
}
这是我的表格视图
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return myarray1.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MycustomCell", for: indexPath) as! MyimagecellTableViewCell
let urlString = "\(myarray2[indexPath.row])"
let url = URL(string: urlString)!
cell.myxcell.kf.setImage(with: url)
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("row: \(myarray2[indexPath.row])")
FetchdataViewController.fullimg = "\(myarray3[indexPath.row])"
FetchdataViewController.thumbimg = "\(myarray2[indexPath.row])"
self.performSegue(withIdentifier: "photofull", sender: self)
}
【问题讨论】:
-
一种方法是使用
queryLimit获取数据,第一次设置查询限制为10,然后第二次设置为20,以此类推
标签: ios firebase swift3 firebase-realtime-database