我在collectionView中有一个tableView。 tableView具有扩展单元格。当我更改第一个单元格中文本字段(数量)中的值时,我希望第二个单元格中的标签更改其值。当“editingChanged”事件触发时,我似乎无法访问该标签(TotalPrice)。请查找附表以了解表格和集合视图的方式以及显示我正在尝试做的图片。
ItemTableCollectionViewCell:
class ItemTableCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var catatitle: UILabel!
@IBOutlet weak var catabanner: UIImageView!
@IBOutlet weak var catatable: UITableView!
}
extension ItemTableCollectionViewCell{
func setTableViewDataSourceDelegate<D: UITableViewDataSource & UITableViewDelegate>(_ dataSourceDelegate: D, forRow row: Int) {
catatable.delegate = dataSourceDelegate
catatable.dataSource = dataSourceDelegate
catatable.tag = row
catatable.setContentOffset(catatable.contentOffset, animated:false) // Stops collection view if it was scrolling.
catatable.reloadData()
}
var tableViewOffset: CGFloat {
set { catatable.contentOffset.x = newValue }
get { return catatable.contentOffset.x }
}
}
CataloguesViewController:这是用于设置集合视图并在每个集合单元格内创建表格
extension CataloguesViewController: UICollectionViewDelegate, UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return slidesTitles.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! ItemTableCollectionViewCell
cell.catatitle.text = slidesTitles[slidepos]
cell.catabanner.image = #imageLiteral(resourceName: "kzn")
cell.setTableViewDataSourceDelegate(self, forRow: indexPath.row)
return cell
}
}
CataloguesViewController:主类
中的tableview func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if itemscurpage[section].opened {
return 2
}else{
return 1
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if itemscurpage[indexPath.section].opened{
itemscurpage[indexPath.section].opened = false
}else{
itemscurpage[indexPath.section].opened = true
}
print("yip")
tableView.reloadData()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell = (tableView.dequeueReusableCell(withIdentifier: "itemcell") as! ItemCell?)!
cell.ItemTitle.text = " " + itemscurpage[indexPath.section].description
cell.ItemDescription.text = itemscurpage[indexPath.section].description
let imageURLs = "~~~" + itemscurpage[indexPath.section].description + ".png"
cell.ItemImage.sd_setImage(with: URL(string: imageURLs))
cell.ItemQuantity.tag = indexPath.section
cell.ItemQuantity.addTarget(self, action: #selector(CataloguesViewController.quantityText), for: .editingChanged)
return cell
}else{
let cellexp = (tableView.dequeueReusableCell(withIdentifier: "itemcell2") as! ItemPriceCell?)!
// cell.ItemPrice.text = String(itemscurpage[indexPath.section].quantity * itemscurpage[indexPath.section].price) this is what I am trying to input into the label
cellexp.cartBtn.tag = indexPath.section
cellexp.cartBtn.addTarget(self, action: #selector(CataloguesViewController.buttonCloicked), for: UIControlEvents.touchUpInside)
return cellexp
}
}
func tableView(_ tableView: UITableView,
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?
{
let closeAction = UIContextualAction(style: .normal, title: "Close", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("OK, marked as Closed")
success(true)
})
return UISwipeActionsConfiguration(actions: [closeAction])
}
}