В настоящее время у меня настроен просмотр изображений, который ссылается на изображение, которое я храню в папке ресурсов. Как можно получить пользовательское изображение из Firebase?
lazy var profileImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "profileUpload")
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
//imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleSelectProfileImageView)))
imageView.isUserInteractionEnabled = true
return imageView
}()
Эта функция ссылается и вытягивает profileImageUrl, который я должен был представить. Как я могу добавить это к моему предыдущему ленивому var?
func fetchUser() {
Database.database().reference().child("users").observe(.childAdded, with: { (snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
let user = User()
user.profileImageUrl = dictionary["profileImageUrl"]as? String
}
}, withCancel: nil)
}
Есть ли способ повторить этот метод, заменив ячейку на imageView? Кажется, намного проще и требует гораздо меньше кода.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! UserCell
cell.textLabel?.textColor = UIColor.white
let user = users[indexPath.row]
cell.textLabel?.text = user.name
cell.detailTextLabel?.text = user.email
cell.detailTextLabel?.textColor = UIColor.white
cell.textLabel?.font = UIFont.boldSystemFont(ofSize: 15.0)
if let profileImageUrl = user.profileImageUrl {
cell.profileImageView.loadImageUsingCacheWithUrlString(profileImageUrl)
}
return cell
}
Приведенный выше код извлекает нужное мне изображение в виде таблицы.