如何访问我的存储并将其放入收藏夹视图

时间:2019-04-26 01:58:34

标签: swift firebase uicollectionview

我被困了几个小时,无法弄清楚。我对编程还是很陌生,也许您可​​以帮助我

我已经创建了一个函数,可以将所有内容上传到Firebase存储中

df = pd.DataFrame(list(myDictionary.values()), index=myDictionary.keys(),
                                                columns=list('ABC'))
df.reset_index(inplace=True)
df = df.replace(r"_[0-9]", "", regex=True)
df.sort_values(by='index', inplace=True)

print(df)
  index   A   B   C
2   ID1   1   2   3
0   ID2  10  11  12
1   ID2   2  34  11
3   ID3   8   3  12
//this is to call the other class
     var discover = MainViewController()


    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
        imageCam.image = image
        MainViewController.stuffImages.append(image)
        MainViewController.Stuff.append("yes")

        picker.dismiss(animated: true, completion: nil)

    }

如何在Firebase中调用我的存储并将其放置在cell.imageView.image

1 个答案:

答案 0 :(得分:0)

我通常要做的是创建一个单独的数据源文件,如下所示。

class DiscoverCollectionDataSource: NSObject, UICollectionViewDataSource {

    private var stuffs: [String]
    private var stuffImages: [UIImage]

    init(stuffs: [String], stuffImages: [UIImage]) {

        self.stuffImages = stuffImages

        super.init()
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.stuffImages.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! DiscoverCollectionViewCell

        cell.gamerShopControllerDelegate = self.gamerShopControllerDelegate

        let stuffTitle = self.stuffs[indexPath.row]
        let stuffImage = self.stuffImages[indexPath.row]

        cell.titleLable.text = stuffTitle
        cell.imageView.image = stuffImage

        return cell

    }

}

之后,您可以在集合视图中链接数据源。

class DiscoverCollectionView: UICollectionViewController {

    // Properties
    var stuffs: [String]
    var stuffImages: [UIImage]

    lazy var dataSource: DiscoverCollectionDataSource = {
        return DiscoverCollectionDataSource(stuffs: self.stuffs, stuffImages: self.stuffImages)
    }()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Collection View
        collectionView?.dataSource = dataSource
    }

}

最后,您可以从DiscoverCollectionView中的API中获取数据,也可以将数据传递到DiscoverCollectionView中。

希望有帮助。