Установить изображение ячейки как изображение профиля пользователя, хранящееся в firebase - PullRequest
0 голосов
/ 31 октября 2018

Добрый день, я пытаюсь разрешить пользователям отображать сохраненное изображение профиля на боковой панели моего приложения. Похоже на твиттер. Когда я запускаю свой код, я получаю сообщение об ошибке и не уверен, как это исправить.

Невозможно преобразовать возвращаемое выражение типа 'String' в тип возвращаемого значения 'UITableViewCell'

Я попытался изучить учебник или даже погуглить, чтобы узнать, сталкивался ли кто-то с той же проблемой. Любая обратная связь или помощь будет принята с благодарностью.

     fetchUser()
}

func fetchUser() {
    Database.database().reference().child("users").observe(.childAdded, with: { (snapshot) in

        if let dictionary = snapshot.value as? [String: AnyObject] {
            let user = User(dictionary: dictionary)
            user.id = snapshot.key
            self.users.append(user)

            DispatchQueue.main.async(execute: {
            })


        }

    }, withCancel: nil)
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: cellId, for: indexPath) as! UserCell
      let user = users[indexPath.row]
    cell.textLabel?.text = user.name
    cell.detailTextLabel?.text = user.email

    if let profileImageUrl = user.profileImageUrl {
        cell.profileImageView.loadImageUsingCacheWithUrlString(profileImageUrl)
    }


    cell.backgroundColor = .clear
    cell.selectionStyle = .none
    if indexPath.row == 0 {

        cell.backgroundColor=UIColor(red: 77/255, green: 77/255, blue: 77/255, alpha: 1.0)
        let cellImg: UIImageView!
        cellImg = UIImageView(frame: CGRect(x: 15, y: 10, width: 80, height: 80))
        cellImg.layer.cornerRadius = 40
        cellImg.layer.masksToBounds=true
        cellImg.contentMode = .scaleAspectFill
        cellImg.layer.masksToBounds=true
        cellImg.image = user.profileImageUrl // here is where the error is 
        cell.addSubview(cellImg)

        let cellLbl = UILabel(frame: CGRect(x: 110, y: cell.frame.height/2-15, width: 250, height: 30))
        cell.addSubview(cellLbl)
        cellLbl.text = titleArr[indexPath.row]
        cellLbl.font=UIFont.systemFont(ofSize: 17)
        cellLbl.textColor=UIColor.white
    } else {
        cell.textLabel?.text=titleArr[indexPath.row]
        cell.textLabel?.textColor=UIColor.white
    }
    return cell
}

Я также выложу картинки, чтобы объяснить, что я имею в виду. Первый - это Твиттер, второй - то, что я хотел бы имитировать.

This is what Twitter looks like

This is what I want to mimic

...