如何在ios(swift)上的tablecell中从firebase读取图像?
我正在尝试读取firebase存储中存储的一些图像 如何才能做到这一点?我正在使用一个适用于Cell的视图 我在牢房里加了一个字母 然后我尝试通过以下方式从存储器调用图像:如何在ios(swift)上的tablecell中从firebase读取图像?,ios,swift,database,firebase,storage,Ios,Swift,Database,Firebase,Storage,我正在尝试读取firebase存储中存储的一些图像 如何才能做到这一点?我正在使用一个适用于Cell的视图 我在牢房里加了一个字母 然后我尝试通过以下方式从存储器调用图像: cell?.imageView?.image = UIImage(named: "gs://mybundefirebase.appspot.com") 无功而返 这是完整的功能,文本标签显示正确,但图像显示不正确 func tableView(_ tableView: UITableView, cellForRowAt i
cell?.imageView?.image = UIImage(named: "gs://mybundefirebase.appspot.com")
无功而返
这是完整的功能,文本标签显示正确,但图像显示不正确
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell")
cell?.textLabel?.text = postData[indexPath.row];
cell?.textLabel?.textAlignment = .center;
cell?.imageView?.image = UIImage(named: "gs://mybundefirebase.appspot.com")
return cell!
}
任何帮助。。。太不可思议了!我在这方面遇到了很多麻烦
谢谢大家
您可以使用这样导入的Firebase:FirebaseStorageUI
import FirebaseStorageUI
用户喜欢这样:
let urlToData = "gs://mybundefirebase.appspot.com" + "/" + folderOfImage + "/" + imageNameOnStorage
let reference = FIRStorage.storage().reference(forURL: urlToData) //ctreates reference to image in storage
let placeholderImage = #imageLiteral(resourceName: "placeholder") //placeholder if wanted
imageView.sd_setImage(with: reference, placeholderImage: placeholderImage) //will set your image for you
这也会将图像缓存在内存中,这样,如果您计划在应用程序中的其他位置检索相同的图像,就不必向存储器发出太多请求
编辑:在您的情况下,urlToData可以等于:
let urlToData = "gs://mybundefirebase.appspot.com/a-chair-bl.jpg"
如果存储器上的图像名称为a-chair-bl.jpg
,并将其放置在根文件夹中,则此操作有效
EDIT2:您可以在cellForRowAt
中调用上述代码,但我不建议这样做。您应该在PostCell
中执行此操作,您应该在那里为它创建一个函数,然后只需从cellForRowAt调用该函数即可
EDIT3:要访问FirebaseStorageUI
,您需要将其添加到pod文件中,然后运行pod安装
pod 'FirebaseUI/Storage'
您可以使用这样导入的Firebase:FirebaseStorageUI
import FirebaseStorageUI
用户喜欢这样:
let urlToData = "gs://mybundefirebase.appspot.com" + "/" + folderOfImage + "/" + imageNameOnStorage
let reference = FIRStorage.storage().reference(forURL: urlToData) //ctreates reference to image in storage
let placeholderImage = #imageLiteral(resourceName: "placeholder") //placeholder if wanted
imageView.sd_setImage(with: reference, placeholderImage: placeholderImage) //will set your image for you
这也会将图像缓存在内存中,这样,如果您计划在应用程序中的其他位置检索相同的图像,就不必向存储器发出太多请求
编辑:在您的情况下,urlToData可以等于:
let urlToData = "gs://mybundefirebase.appspot.com/a-chair-bl.jpg"
如果存储器上的图像名称为a-chair-bl.jpg
,并将其放置在根文件夹中,则此操作有效
EDIT2:您可以在cellForRowAt
中调用上述代码,但我不建议这样做。您应该在PostCell
中执行此操作,您应该在那里为它创建一个函数,然后只需从cellForRowAt调用该函数即可
EDIT3:要访问FirebaseStorageUI
,您需要将其添加到pod文件中,然后运行pod安装
pod 'FirebaseUI/Storage'
嗨,约翰,谢谢你。我试图做到的是:在我的数据库中,我有不同的帖子(在下面的截图中称为“视频”),包含不同的信息。我希望,对于帖子,能够从firebase存储中分配一个图像。示例:在下面的屏幕截图中,在数据库Videos,1,image中,我添加了值“gs://bundleid.appspot.com/a-chair-bl.jpg”来调用该图像。然后我想调用表格单元格中的图像,此时只调用标题。我应该将代码放在哪里才能使其工作?在同一个功能中?它似乎不起作用:(感谢您一直以来的lto,我真的很感激!对于一个好的体系结构,您要分配给帖子的图像应该位于存储中的一个名为“PostImages”的新文件夹中,例如,您的图像可能有一个预定义的名称,如postid,它是“PostDimage”的一部分,让我试试所有这些,然后我回到你这里:)我的想法是我可以在firebase数据库中添加新的“视频”,这样它将是动态的。我想为此我需要将代码保留为let urlToData=“gs://mybundefirebase.appspot.com”+“/”+folderOfImage+“/”+imagenameostorage,它将从我的截图中获取我在数据库中添加的链接?谢谢:)似乎我在swift中找不到FirebaseStorageUI:(嗨,约翰,谢谢你。我试图实现以下目标:在我的数据库中,我有不同的帖子(在下面的屏幕截图中称为“视频”)使用不同的信息。我希望帖子能够从firebase存储中分配图像。例如:在下面的屏幕截图中,在数据库中,视频,1,图像中,我添加了值“gs://bundleid.appspot.com/a-chair-bl.jpg”调用图像。然后我想调用表单元格中的图像,此时仅调用标题。我应该将代码放在哪里使其工作?在同一个函数中?它似乎不工作:(感谢您一直以来的lto,我真的很感激!对于一个好的体系结构,您要分配给帖子的图像应该位于存储中的一个名为“PostImages”的新文件夹中,例如,您的图像可能有一个预定义的名称,如postid,它是“PostDimage”的一部分,让我试试所有这些,然后我回到你这里:)我的想法是我可以在firebase数据库中添加新的“视频”,这样它将是动态的。我想为此我需要将代码保留为let urlToData=“gs://mybundefirebase.appspot.com”+“/”+folderOfImage+“/”+imagenameostorage,它将从我的截图中获取我在数据库中添加的链接?谢谢:)似乎我在swift中找不到FirebaseStorageUI:(