提取孩子的参数与获取没有参数的孩子有什么不同?

时间:2019-07-14 21:48:48

标签: ios swift iphone firebase firebase-realtime-database

我对其进行了更改,以使孩子具有多个参数(图像和标题),而不仅仅是图像孩子。

这就是我的相关代码。


class MyUser {
    var UserFirstName: String?
    var PhotoPosts: String?
    init(UserFirstName: String?, Photos: String?) {
        self.Photos = Photos
        self.UserFirstName = UserFirstName
    }
}

var peeps = [MyUser]()

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

    let image1 = cell.viewWithTag(1) as! UIImageView

    let person: MyUser = peeps[indexPath.row]


    cell.lblName.text = person.UserFirstName

    if let Photos = person.Photos {
        let url = URL(string: Photos)
        image1.sd_setImage(with: url)
    }

    return cell

}

还有

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

    for peeps in snapshot.children.allObjects as! [DataSnapshot] {
        if peeps.key != thisUsersUid {
            let peepsObject = people.value as? [String: AnyObject]
            let peepsUserFirstName = peopleObject?["UserFirstName"] as? String
            let peepsPhotos = peopleObject?["Photos"]  as? String
            let RAA = MyUsers(Photos: peepsPhotos, UserFirstName: peepsUserFirstName)
            self.peeps.append(RAA)

        }
        self.table.reloadData()
    }
}

我希望它获取子对象的image参数,而不是仅在子引用后面查找图像。

0 个答案:

没有答案