如何将单元格中单击的按钮上的数据传递到另一个添加到购物车页面的表格视图?

问题描述 投票:0回答:1

enter image description hereenter image description here

import Foundation
import UIKit
import PanModal

var sum = ""

class CustomBottomSheet: UITableViewController {
    
    @IBOutlet weak var cartTitle: UILabel!
    
    @IBOutlet weak var titleLBbottom: UILabel!
    //가격
    @IBOutlet weak var priceLBbottom: UILabel!
    
    @IBOutlet weak var wonLB: UILabel!
    
    @IBOutlet weak var totalLB: UILabel!
    //🐶 입력갯수
    @IBOutlet weak var countLB: UILabel!
    
    @IBOutlet weak var gaeLB: UILabel!
    
    @IBOutlet weak var addtoCartPage: UIButton!
    
    
    @IBOutlet weak var stepper: UIStepper!
    
    //⭐️ let sum
    @IBAction func stepperValueChanged(_ sender: UIStepper) {
        
        let price = MenuData.MenuDATAS[index].price
        let sum = Int(sender.value) * price
        
        countLB.text = Int(sender.value).description
        priceLBbottom.text = String(sum)
        
    }
    
    var index: Int = 0
    
    var collectMemuData: [MenuData] = []
    
    var quantity: Int = 0
    
    override func viewDidLoad() {
        super.viewDidLoad()
        collectMemuData = MenuData.MenuDATAS
        
        stepperSetup()
        updatePriceLabel()
        
    }
    
    func bottomsetup(with menuData: MenuData){
        titleLBbottom.text = menuData.title
        priceLBbottom.text = String(menuData.price)
        
        
    }
    
    func stepperSetup() {
        stepper.wraps = true
        stepper.autorepeat = true
        stepper.minimumValue = 0
        stepper.maximumValue = 15
        stepper.value = 0
    }
    
    @IBAction func addtoCartPageSELELTED(_ sender: UIButton) {
        print("버튼이 눌림")
    }
     
}

extension CustomBottomSheet: PanModalPresentable {
    var panScrollable: UIScrollView? {
        return tableView
    }
    
    var shortFormHeight: PanModalHeight {
        return .contentHeight(200)
    }
    
    var longFormHeight: PanModalHeight {
        return .maxHeightWithTopInset(40)
        
    }
    
    func calculatePrice(for quantity: Int) -> Double {
        let basePrice = 10.0
        let pricePerItem = 2.0
        return basePrice + (Double(quantity) * pricePerItem)
        
    }
    
    func updatePriceLabel() {
        let price = calculatePrice(for: quantity)
        priceLBbottom.text = String(format: "A", price)
    }
    
}

import UIKit

class ADDTableViewCell: UITableViewCell {
    
    @IBOutlet weak var addTitleLB: UILabel!
    
    @IBOutlet weak var totalcountLB: UILabel!
    
    @IBOutlet weak var totalPriceLB: UILabel!
    
}

import UIKit

class AddviewController: UIViewController {
    
    @IBOutlet weak var addTableView: UITableView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        addTableView.dataSource = self
        
    }
    
    override func viewWillAppear(_ animated: Bool) {
        addTableView.reloadData()
    }
    
}

extension AddviewController: UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "ADDTableViewCell", for: indexPath) as! ADDTableViewCell
        
        return cell
    }
}

导入 UIKit

我想知道在单元格中单击“添加到购物车”按钮(在 CustomBottomSheet 中)的传递数据到另一个添加到购物车页面的表视图(addTableView,ADDTableViewCell)

因为这个问题,我头疼得很厉害。 请帮助我..

按钮(在 CustomBottomSheet 中)-> (addTableView,ADDTableViewCell)

ios swift uitableview replace shopping-cart
1个回答
0
投票

你试过tableView(_:didSelectRowAt:)方法了吗?这允许您将单元格中的选定数据传递给另一个视图控制器。

© www.soinside.com 2019 - 2024. All rights reserved.