Swift TableView单元格中的TableView不显示单元格

Swift TableView单元格中的TableView不显示单元格,swift,uitableview,tableview,datasource,tableviewcell,Swift,Uitableview,Tableview,Datasource,Tableviewcell,我在UITableviewCell中有一个UITableView。这是我的密码: UITableViewCell: class ProductViewCell: UITableViewCell { @IBOutlet weak var totalOrderButton: UIButton! @IBOutlet weak var productImage: UIImageView! @IBOutlet weak var productNameLabel: UILabel! @IBOutlet w

我在UITableviewCell中有一个UITableView。这是我的密码:

UITableViewCell:

class ProductViewCell: UITableViewCell {

@IBOutlet weak var totalOrderButton: UIButton!
@IBOutlet weak var productImage: UIImageView!
@IBOutlet weak var productNameLabel: UILabel!
@IBOutlet weak var productSubNameLabel: UILabel!
@IBOutlet weak var productBioLabel: UILabel!
@IBOutlet weak var mlButton: UIButton!
@IBOutlet weak var productQuantity: UILabel!
@IBOutlet weak var plusButton: UIButton!
@IBOutlet weak var minusButton: UIButton!
@IBOutlet weak var greenHeartButton: UIButton!
@IBOutlet weak var liquorsTableView: UITableView!

var fourLiquorStores: [LiquorStore] = []

var currentUser: User!

var currentProduct: Product! {
    didSet {
        updateUI()
    }
}

func updateUI() {
    downloadProductImage()
    productNameLabel.text = currentProduct.name
    productSubNameLabel.text = currentProduct.subName
    productBioLabel.text = currentProduct.description
    productQuantity.text = "\(currentProduct.quantity)"
    updateGreenHeart()

}
var cache = SAMCache.shared()
weak var delegate: ProductViewCellDelegate!

override func awakeFromNib() {
    super.awakeFromNib()
    liquorsTableView.estimatedRowHeight = 65
    liquorsTableView.rowHeight =  65
    liquorsTableView.delegate = self
    liquorsTableView.dataSource = self
    fetchLiquorStores()
}

func fetchLiquorStores() {
      LiquorStore.observeNewLiquorStore { (liquorStore) in
        LiquorStore.observeNewLiquorStore { (liquorStore) in
            if !self.fourLiquorStores.contains(liquorStore) {
                self.fourLiquorStores.append(liquorStore)
                self.delegate.updateTableView()
                print(self.fourLiquorStores)
            }
        }
    }
}




func downloadProductImage() {
    let productuid = currentProduct.uid
    let profileImageKey = "\(productuid)"

    if let image = cache?.object(forKey: profileImageKey) as? UIImage {
        productImage.image = image
    } else {
    currentProduct.downloadPopularProductImage { [weak self] (image, error) in
        if let error = error {
            print(error.localizedDescription)
        } else {
            self?.productImage.image = image
            self?.cache?.setObject(image, forKey: profileImageKey)
        }
    }
    }
}


// Ad o delete Quantities
@IBAction func plusDidTap() {
    if currentProduct.quantity >= 1 && currentProduct.quantity <= 60 {
        currentProduct.quantity += 1
        delegate.updateTableView()

    }
}

@IBAction func minusDidTap() {
    if currentProduct.quantity > 1 {
        currentProduct.quantity -= 1
        delegate.updateTableView()
    }
}


func updateGreenHeart() {
    if let currentUser = currentUser {
        if currentUser.favoriteProducts.contains(currentProduct) {
            greenHeartButton.setImage(#imageLiteral(resourceName: "GreenHeartFilled"), for: [])
        } else {
            greenHeartButton.setImage(#imageLiteral(resourceName: "GreenHeart"), for: [])
        }
    }
}

// Ad or delete Favorite Products
@IBAction func greenHeartDidTap() {
    if currentUser.favoriteProducts.contains(currentProduct) {
        self.greenHeartButton.setImage(#imageLiteral(resourceName: "GreenHeart"), for: [])
        self.currentUser.deleteFavoriteProduct(product: currentProduct)
    } else {
        self.greenHeartButton.setImage(#imageLiteral(resourceName: "GreenHeartFilled"), for: [])
        self.currentUser.addFavoriteProduct(product: currentProduct)

    }
}
}

UITablViewCell-2:

class LiquorStoresViewCell: UITableViewCell {

@IBOutlet weak var liquorStoreNameLabel: UILabel!
@IBOutlet weak var liquorStorePriceLabel: UILabel!
@IBOutlet weak var liquorStoreTimeLabel: UILabel!
@IBOutlet weak var starStackView: UIStackView!
@IBOutlet weak var imageViewBoard: UIImageView!

var currentProduct: Product!
var currentPriceIndex: Int = 0

var liquorStore: LiquorStore! {
    didSet {
        updateUI()
    }
}



func updateUI() {
changeLiquorStoreProductsUid()
liquorStoreNameLabel.text = liquorStore.userName
let index = liquorStore.products.index(of: currentProduct)
    if let index = index {
        let productPrice = liquorStore.products[index].price[currentPriceIndex]
       format(price: productPrice)
    }
}



// Format Product Price to Currency
func format(price: Double)  {
    let formatter = NumberFormatter()
    formatter.locale = Locale.current // Change this to another locale if you want to force a specific locale, otherwise this is redundant as the current locale is the default already
    formatter.numberStyle = .currency
    if let formattedTipAmount = formatter.string(from: price as NSNumber) {
        liquorStorePriceLabel.text = "Tip Amount: \(formattedTipAmount)"
    }
}

// Func to organize LiquorStores
func changeLiquorStoreProductsUid () {
    for product in liquorStore.products {
        if self.currentProduct.name == product.name && self.currentProduct.description == product.description && self.currentProduct.subName == product.subName {
            let index = liquorStore.products.index(of: product)
            if let index = index {
                liquorStore.products[index].uid = currentProduct.uid
            }
        }
    }
}



override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    liquorStorePriceLabel.textColor = UIColor.white
    liquorStoreNameLabel.textColor = UIColor.white
    liquorStoreTimeLabel.textColor = UIColor.white
    imageViewBoard.backgroundColor = #colorLiteral(red: 0.5239839702, green: 0.5239839702, blue: 0.5239839702, alpha: 1)
    for view in starStackView.subviews {
        let image = view as! UIImageView
        image.image = #imageLiteral(resourceName: "WhiteStar")
    }

}
}

UITableView单元格内的UITableView不显示以下数据:/ 有什么问题吗

这就是我正在构建的:

模拟器中会出现一个this,如您所见,第二个tableview为空:

PD:我正在从firebase成功下载LixorStores。

虽然可以完成您正在尝试的工作,但完全重新思考您的体系结构会简单得多。如果视图控制器只显示一个产品,加上一个酒类商店列表,那么产品视图实际上不应该位于单元格中——只需将其设置为普通视图,并将该视图设置为表头。这些单元将成为酒类商店,您不再需要在单元中嵌套桌子。或者,您可以将产品视图保留在单元格中,但只需将酒类商店的原型作为第二种单元格添加到同一个表中

编辑:现在你已经发布了你的故事板截图,最简单的方法就是将你的酒类商店原型单元格向上移动到顶层表格,从顶层单元格中删除子表格,然后在你的数据源中

func tableView(_ tableView: UITableView, cellForRowAtIndexPath path: NSIndexPath) -> UITableViewCell {
    if path.row == 0 {
        return tableView.dequeueCellWithIdentifier("productDetailsCell")!
    } else {
        return tableView.dequeueCellWithIdentifier("liquorStoreCell")!
    }
}
虽然可以做您正试图做的事情,但完全重新思考您的体系结构要简单得多。如果视图控制器只显示一个产品,加上一个酒类商店列表,那么产品视图实际上不应该位于单元格中——只需将其设置为普通视图,并将该视图设置为表头。这些单元将成为酒类商店,您不再需要在单元中嵌套桌子。或者,您可以将产品视图保留在单元格中,但只需将酒类商店的原型作为第二种单元格添加到同一个表中

编辑:现在你已经发布了你的故事板截图,最简单的方法就是将你的酒类商店原型单元格向上移动到顶层表格,从顶层单元格中删除子表格,然后在你的数据源中

func tableView(_ tableView: UITableView, cellForRowAtIndexPath path: NSIndexPath) -> UITableViewCell {
    if path.row == 0 {
        return tableView.dequeueCellWithIdentifier("productDetailsCell")!
    } else {
        return tableView.dequeueCellWithIdentifier("liquorStoreCell")!
    }
}

有截图吗?我没有看到一个。可能的重复可能的重复我把截图放在“故事板”和“模拟器”链接中我喜欢酒类商店阵列被称为
fourlikorstores
:有截图吗?我没有看到一个。可能的重复可能的重复我把截图放在“故事板”和“模拟器”链接中我喜欢酒类商店阵列被称为
fourlikorstores
:再见!!这就是我需要的,非常感谢你!!很高兴它有帮助!伟大的这就是我需要的,非常感谢你!!很高兴它有帮助!