为什么Firebase图像(通过SdWebImage)加载缓慢?

时间:2020-03-14 12:08:40

标签: ios swift firebase-realtime-database sdwebimage

使用Firebase和SD Web图像。因此,此代码可以正常工作,但它总是具有需要花费很长时间加载的2或3个散乱图像?我可能是错的,但是当我不在屏幕上滚动时,加载速度可能会变慢。这可能只是一个错误的判断,但这是我观察到的。

class peopleWhoLikedMe: UITableViewController, CLLocationManagerDelegate{

let locationManager = CLLocationManager()
var latestLocation: [String: Double]?
let locCoord1 = CLLocation()

@IBOutlet weak var border: UIImageView!

func printPersonInfo(uid: String) {

    DispatchQueue.main.async{

    print(uid)
    let usersRef = Database.database().reference().child("people")
    let thisUser = usersRef.child(uid)
    thisUser.observeSingleEvent(of: .value, with: { snapshot in
        let photoPosts = snapshot.childSnapshot(forPath: "PhotoPosts").value as? String ?? "No PhotoPosts"
        let education = snapshot.childSnapshot(forPath: "Education").value as? String ?? "No Education"
        let whatIamConsideringBuying = snapshot.childSnapshot(forPath: "WhatIamConsideringBuying").value as? String ?? "No WhatIamConsideringBuying"
        print(photoPosts, education, whatIamConsideringBuying)
        let p = Usery(education: education, whatIamConsideringBuying: whatIamConsideringBuying, photoPosts: photoPosts)
        self.person.insert(p, at: 0)
         self.table.reloadData()

    })
}

}
var immy: UIImage!
var imageURLs = [String]()

var refArtists : DatabaseReference!

@IBOutlet weak var table: UITableView!
var people = [Userx]()
var person = [Usery]()

public override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {


    return person.count

}

public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ViewControllerTableViewCell

    let immy = cell.viewWithTag(2) as! UIImageView

    let person1: Usery = person[indexPath.row]


    cell.lblName1.text = person1.education
    cell.lblgenre1.text = person1.whatIamConsideringBuying

    if let photoPosts = person1.photoPosts {
        let url = URL(string: photoPosts)
        immy.sd_setImage(with: url)
    }

    return cell

}

以上是我认为唯一的相关代码。我只是添加以下内容,以防丢失某些内容。

    refArtists.observe(DataEventType.value,  with: {snapshot in

        if snapshot.childrenCount>0{

            self.people.removeAll()

            for people in snapshot.children.allObjects as! [DataSnapshot] {
                if people.key != thisUsersUid { //do not add this users info to the array
                    let peopleObject = people.value as? [String: AnyObject]
                    let peopleEducation = peopleObject?["Education"] as? String
                    let peopleWhatIamConsideringBuying = peopleObject?["WhatIamConsideringBuying"] as? String
                    let peoplePhotoPosts = peopleObject?["PhotoPosts"]  as? String
                    let peopleimageDownloadURL = peopleObject?["imageDownloadURL"] as? String
                    let peoplepostID = peopleObject?["postID"] as? String
                    let peoplecaption = peopleObject?["caption"] as? Int

                    let peoplepeopleWhoLike = peopleObject?["peopleWhoLike"] as? String
                    let peopleCoordinates = peopleObject?["Coordinates"] as? String
                                            ///belowIsJustJunkCode
                    let userId = people.key
                    let coordSnap = people.childSnapshot(forPath: "Coordinates")
                    let lat = coordSnap.childSnapshot(forPath: "latitude").value as! CLLocationDegrees
                    let lon = coordSnap.childSnapshot(forPath: "longitude").value as! CLLocationDegrees
                    let locCoord = CLLocation(latitude: lat, longitude: lon)
                    print(userId, "coords: \(lat)  \(lon)")



                    let distance = locCoord.distance(from: self.locCoord1)
                    print(distance, "distance")


                    let peopl = Userx(Education: peopleEducation, WhatIamConsideringBuying: peopleWhatIamConsideringBuying, PhotoPosts: peoplePhotoPosts, imageDownloadURL: peopleimageDownloadURL, postID: peoplepostID, peopleWhoLike: peoplepeopleWhoLike, Coordinates: peopleCoordinates, distance:distance, caption: peoplecaption)

                        self.people.append(peopl)

0 个答案:

没有答案