I wrote a function to add a Cell in a UITableView
.
numberOfRowsInSection
works but cellForRowAt
does not work.
class ShopMenuViewCell: UITableViewCell {
@IBOutlet weak var menuTableView: UITableView!
var menuPrice: MenuPrice!
override func awakeFromNib()
{
super.awakeFromNib()
}
}
extension ShopMenuViewCell
{
func setView()
{
self.menuTableView.delegate = self
self.menuTableView.dataSource = self
self.menuTableView.regCells(cells: ["ShopMenuInformationCell"])
DispatchQueue.main.async
{
self.menuTableView.reloadData()
}
}
}
extension ShopMenuViewCell : UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "ShopMenuInformationCell", for: indexPath) as? ShopMenuInformationCell,
let menu = self.menuPrice,
let name = menu.name,
let price = menu.amt else { return ShopMenuInformationCell() }
return cell
}
}
In ShpMenuInformationCell.swift
class ShopMenuInformationCell: UITableViewCell
{
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var shopNameLabel: UILabel!
@IBOutlet weak var menuNameLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
override func awakeFromNib()
{
super.awakeFromNib()
}
}
I saw the answer to add a ViewController
, but I do not know what to do because it is not a storyboard. (.xib)
I think it is because I add UITableViewCell
in the UITableViewCell
class.
Do you know why?