gpt4 book ai didi

ios - 将 swift 连接到 FirebaseDatabase

转载 作者:行者123 更新时间:2023-11-30 11:59:46 26 4
gpt4 key购买 nike

想要将此代码连接到 FirebaseDatabase。但我在连接时遇到错误。

错误:- 无法将“[Datasnapshot]”类型的值转换为预期的参数类型“UView”。

FirebaseDatabase

Below is Code snippet of it.

import UIKit
import FirebaseDatabase
import FirebaseAuth

class HomeViewController: UIViewController, iCarouselDelegate, iCarouselDataSource
{

@IBOutlet var carouselView: iCarousel!

var snaps : [DataSnapshot] = []
override func viewDidLoad() {
super.viewDidLoad()
if let currentUserUid = Auth.auth().currentUser?.uid {
Database.database().reference().child("posts").child("photoUrl").observe(.childAdded, with: { (snapshot) in
self.snaps.append(snapshot)
self.carouselView.reloadData()
})
}

carouselView.type = .coverFlow
}

func numberOfItems(in carousel: iCarousel) -> Int {
return snaps.count
}

func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
let tempView = UIView(frame: CGRect(x: 0, y: 0, width: 374, height: 417))
tempView.addSubview(snaps)
return tempView
}

func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
if option == iCarouselOption.spacing {
return value * 2.1
}
return value
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

最佳答案

该错误清楚地表明您正在将快照值添加到 UIView 中。

tempView.addSubview(snaps)

上面代码中的 snaps 是一个 DataSnapshot 类型的数组。您不能将 DataSnapshot 数组添加为 subview 。

关于ios - 将 swift 连接到 FirebaseDatabase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47389962/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com