快速步进动作,可在同一单元格内更改UITextField和UILabel [英] Swift Stepper Action that changes UITextField and UILabel within same cell

查看:87
本文介绍了快速步进动作,可在同一单元格内更改UITextField和UILabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个函数来构建我的自定义单元格.用于创建单元格的函数是"makeMyList".我已成功完成的stepper会递增和递减itemQuantity文本字段.我遇到的麻烦是更新"itemPrice"标签.我希望itemPrice.text为数量*价格,并随着数量的动态上升或下降而动态更新.

I am using a function to build my custom cell. the function used to create the cell is "makeMyList". The stepper I have successfully increments and decrements the itemQuantity textField. The trouble I am having comes with updating the "itemPrice" label. I want itemPrice.text to be quantity * price and update dynamically as the quantity either goes up or down dynamically.

有人可以帮助我实现这一目标吗?

Could someone possibly help me with how to get this to happen?

提前谢谢!

class MyListTableViewCell: UITableViewCell
{
    @IBOutlet weak var itemPrice: UILabel!
    @IBOutlet weak var itemName: UILabel!
    @IBOutlet weak var itemQuantity: UITextField!
    @IBOutlet weak var stepper: UIStepper!

    @IBAction func itemQuantityStepper(sender: UIStepper)
    {
        self.itemQuantity.text = Int(sender.value).description
    }

    override func awakeFromNib() {
        super.awakeFromNib()
    }

    func makeMyList(myItem: MyList)
    {
        self.itemName.text = myItem.MyItemName
        self.itemPrice.text = String(stepper.value * Double(myItem.MyItemPrice))
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
}

推荐答案

适用于遇到相同问题的任何人.这是我自己的问题的答案.

For anyone who has the same issue. Here is the answer to my own question.

希望有帮助!

class MyListTableViewCell: UITableViewCell
{
    @IBOutlet weak var itemPrice: UILabel!
    @IBOutlet weak var itemName: UILabel!
    @IBOutlet weak var itemQuantity: UITextField!
    @IBOutlet weak var stepper: UIStepper!

    var price: Float = 0.0
    var quantity: Int = 1


    override func awakeFromNib() {
        super.awakeFromNib()
    }

    func makeMyList(myItem: MyList)
    {
        self.itemName.text = myItem.MyItemName
        self.itemPrice.text = myItem.MyItemPrice

        price = Float(myItem.MyItemPrice)
    }

    @IBAction func itemQuantityStepper(sender: UIStepper)
    {
        quantity = Int(sender.value)
        self.itemQuantity.text = String(quantity)
        self.itemPrice.text = price * Float(quantity)
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
}

这篇关于快速步进动作,可在同一单元格内更改UITextField和UILabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆