Ios 无法在单元格中获取imageview的下载url
目前我遇到了一个问题,我已将firebase连接到我的应用程序,创建了能够将图像发布到firebase的用户,并通过帖子循环找到以下用户以创建提要。只有一个问题,我一直在遵循一个教程来制作提要部分,其中包括一个void=downloadurl(带:String),我找不到这个函数。我已经导入了相同的模块,应用程序几乎被克隆到了他的。我很困惑,希望有人能帮忙。以下是当前的collectionview单元格:Ios 无法在单元格中获取imageview的下载url,ios,swift,image,firebase,Ios,Swift,Image,Firebase,目前我遇到了一个问题,我已将firebase连接到我的应用程序,创建了能够将图像发布到firebase的用户,并通过帖子循环找到以下用户以创建提要。只有一个问题,我一直在遵循一个教程来制作提要部分,其中包括一个void=downloadurl(带:String),我找不到这个函数。我已经导入了相同的模块,应用程序几乎被克隆到了他的。我很困惑,希望有人能帮忙。以下是当前的collectionview单元格: func collectionView(_ collectionView: UICol
func collectionView(_ collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return posts.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt
indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell",
for: indexPath) as! UserFeedCollectionViewCell
-> cell.myImage. downloadImage(from: String) <- does not exist, or
doesn't show up.
cell.myImage.layer.cornerRadius = 12.0
cell.myImage.clipsToBounds = true
return cell
func collectionView(collectionView:UICollectionView,
NumberOfItemsSection:Int)->Int{
返回岗位数
}
func collectionView(collectionView:UICollectionView,cellForItemAt
indexPath:indexPath)->UICollectionViewCell{
let cell=collectionView.dequeueReusableCell(withReuseIdentifier:“cell”,
for:indexath)as!UserFeedCollectionViewCell
->cell.myImage.downloadImage(from:String)这不是内置函数,也不是Firebase或iOS固有的功能。在视频中,作者提到他在以前的视频中创建了此函数,因此您可能应该找到他以前的视频和/或下载最终项目,看看他做了什么
(还有很多类似的第三方库为您提供了一些类似的工具——您可能也想看看其中的一个。)这不是Firebase或iOS固有的内置函数或任何东西。在视频中,作者提到他在以前的视频中创建了此函数,因此您可能应该找到他以前的视频和/或下载最终项目,看看他做了什么
(也有很多类似的第三方库为您提供了一些类似的工具,您可能还想看看其中的一个。)以下是downloadImage
函数的代码。它是UIImageView的扩展。该扩展应该放在任何类之外
class UsersViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
// deleted to save space
}
extension UIImageView {
func downloadImage(from imgURL: String!) {
let url = URLRequest(url: URL(string: imgURL)!)
let task = URLSession.shared.dataTask(with: url) {
(data, response, error) in
if error != nil {
print(error!)
return
}
DispatchQueue.main.async {
self.image = UIImage(data: data!)
}
}
task.resume()
}
}
以下是downloadImage
函数的代码。它是UIImageView的扩展。该扩展应该放在任何类之外
class UsersViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
// deleted to save space
}
extension UIImageView {
func downloadImage(from imgURL: String!) {
let url = URLRequest(url: URL(string: imgURL)!)
let task = URLSession.shared.dataTask(with: url) {
(data, response, error) in
if error != nil {
print(error!)
return
}
DispatchQueue.main.async {
self.image = UIImage(data: data!)
}
}
task.resume()
}
}
试着看第1、2和3集。试着看第1、2和3集。非常感谢