Swift 5.3 UITableView - 使用 UIStepper

问题描述

所以我有一个 UITableView自定义对象和 Kratom 数组填充。在 Kratom 对象中,我有一个名为 size 的属性。这是一个 Int 数组。 Kratom 对象中的每个元素都是它自己的部分。那么sizes属性的每个元素就是行。

每个单元格都有一个可以更改大小值的 UIStepper。我已经让它工作了,然后我只使用和 Int。

我不确定如何访问自定义单元格中的大小数组并更新值。

下面的代码是我在使用 Kratom 对象之前的实现。它正在使用 Product 对象,我想将其更新为 Kratom 以用于其他目的 产品:

class Product {
    var qty: Int
    
    init(newQty: Int) {
        qty = newQty
    }
}

InventoryTableViewCell:

    var productQty: Product! {
        didSet {
            inventoryStepper.value = Double(productQty.qty)
            inventoryLbl.text = String(productQty.qty)
        }
    }
    
    @IBAction func stepperAction(_ sender: UIStepper) {
        productQty.qty = Int(sender.value)
        self.inventoryLbl.text = String(Int(sender.value))
    }

视图控制器:

   func tableView(_ tableView: UITableView,cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "inventoryCell",for: indexPath) as! InventoryTableViewCell
        if productTypes.selectedSegmentIndex == 0 {
            if indexPath.section == 0 || indexPath.section == 2 {
                cell.itemLbl.text = capsules[indexPath.row]
            } else {
                cell.itemLbl.text = productSize[indexPath.row]
            }
            
            cell.productQty = redValues[indexPath.section][indexPath.row]
        } else if productTypes.selectedSegmentIndex == 1 {
            cell.itemLbl.text = productSize[indexPath.row]
            cell.productQty = whiteValues[indexPath.section][indexPath.row]
        } else if productTypes.selectedSegmentIndex == 2 {
            if indexPath.section == 3 || indexPath.section == 5 {
                cell.itemLbl.text = capsules[indexPath.row]
            } else {
                cell.itemLbl.text = productSize[indexPath.row]
            }
            
            cell.productQty = greenValues[indexPath.section][indexPath.row]
        } else if productTypes.selectedSegmentIndex == 3 {
            if indexPath.section == 5 {
                cell.itemLbl.text = productSize[1]
            } else {
                cell.itemLbl.text = productSize[indexPath.row]
            }
            
            cell.productQty = otherValues[indexPath.section][indexPath.row]
        } else if productTypes.selectedSegmentIndex == 4 {
            if indexPath.section == 0 {
                cell.itemLbl.text = sanitizer[indexPath.row]
            } else if indexPath.section == 1 {
                cell.itemLbl.text = hemp[indexPath.row]
            } else if indexPath.section == 2 {
                cell.itemLbl.text = other[indexPath.row]
            }
            
            cell.productQty = specialtyValues[indexPath.section][indexPath.row]
        }
        
        return cell
    }

为此目的。假设 Kratom 与 Product 相同,除了 qty 现在是尺寸,现在是 [Int] 而不是 Int。

我不知道要获取 InventoryTableViewCell 以查看被按下的 UIStepper 的 indexPath 是什么。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...