Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 步进器增加标签的值,然后乘以数组中init函数内部的值_Ios_Swift_Uitableview - Fatal编程技术网

Ios 步进器增加标签的值,然后乘以数组中init函数内部的值

Ios 步进器增加标签的值,然后乘以数组中init函数内部的值,ios,swift,uitableview,Ios,Swift,Uitableview,我的桌面视图单元格 class Service1TableViewCell: UITableViewCell { @IBOutlet weak var quantityStepper: UIStepper! @IBOutlet weak var Service1image: UIImageView! @IBOutlet weak var serviceTitle: UILabel! @IBOutlet weak var pricingInfo: UILabel! @IBOutlet weak

我的桌面视图单元格

class Service1TableViewCell: UITableViewCell {

@IBOutlet weak var quantityStepper: UIStepper!
@IBOutlet weak var Service1image: UIImageView!
@IBOutlet weak var serviceTitle: UILabel!
@IBOutlet weak var pricingInfo: UILabel!
@IBOutlet weak var stepperLabel: UILabel!



func setService1(Dry: Service1){
    Service1image.image = Dry.service1image
    pricingInfo.tag = Dry.service1Pricing
    serviceTitle.text = Dry.service1Title
}
//save data from each cell and multiply for total service


override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

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

    // Configure the view for the selected state
}
@IBAction func valueChanged(_ sender: AnyObject) {
    print("Method .valueChanged activated")

    //Update stepperlabel
    stepperLabel.text = String(Int(quantityStepper.value))

}
}
视图控制器

class Service1ViewController: UIViewController {

@IBOutlet weak var service1TableView: UITableView!

@IBOutlet weak var service1Total: UILabel!


var Dry: [Service1] = []

var step = [Stepper]()

override func viewDidLoad() {
    super.viewDidLoad()

    Dry = Options()



}
func Options() -> [Service1]{

    var dryOptions: [Service1] = []

    let option1 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option2 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option3 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option4 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option5 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option6 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option7 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option8 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option9 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option10 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option11 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option12 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option13 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option14 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option15 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option16 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option17 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option18 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option19 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option20 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option21 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option22 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option23 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option24 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option25 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option26 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option27 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option28 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option29 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option30 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))
    let option31 = Service1(titled: "Test", pricing: Int(5.29), image: #imageLiteral(resourceName: "Test"))

    dryOptions.append(option1)
    dryOptions.append(option2)
    dryOptions.append(option3)
    dryOptions.append(option4)
    dryOptions.append(option5)
    dryOptions.append(option6)
    dryOptions.append(option7)
    dryOptions.append(option8)
    dryOptions.append(option9)
    dryOptions.append(option10)
    dryOptions.append(option11)
    dryOptions.append(option12)
    dryOptions.append(option13)
    dryOptions.append(option14)
    dryOptions.append(option15)
    dryOptions.append(option16)
    dryOptions.append(option17)
    dryOptions.append(option18)
    dryOptions.append(option19)
    dryOptions.append(option20)
    dryOptions.append(option21)
    dryOptions.append(option22)
    dryOptions.append(option23)
    dryOptions.append(option24)
    dryOptions.append(option25)
    dryOptions.append(option26)
    dryOptions.append(option27)
    dryOptions.append(option28)
    dryOptions.append(option29)
    dryOptions.append(option30)
    dryOptions.append(option31)

    return dryOptions

}

}
extension Service1ViewController: UITableViewDataSource, UITableViewDelegate{


func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return Dry.count

}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let Dry1 = Dry[indexPath.row]
    let cell = tableView.dequeueReusableCell(withIdentifier: "Service1Cell") as! Service1TableViewCell
    cell.setService1(Dry: Dry1)
    cell.stepper = step[indexPath.row]
    return cell
}

// send selected data to cart
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


}


}
(cart tableView)服务选择单元

class CartTableViewCell: UITableViewCell {

@IBOutlet weak var serviceChoiceImage: UIImageView!
@IBOutlet weak var serviceChoiceTitle: UILabel!
@IBOutlet weak var serviceChoiceAmount:UILabel!
@IBOutlet weak var serviceChoicePrice: UILabel!



override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

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

    // Configure the view for the selected state
}

}
(购物车表视图)订单总数单元格

class CartTotalTableViewCell: UITableViewCell {

@IBOutlet weak var orderTotal: UILabel!
@IBOutlet weak var OrderTax: UILabel!
@IBOutlet weak var deliveryFee: UILabel!
@IBOutlet weak var grandTotal: UILabel!


override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

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

    // Configure the view for the selected state
}

}

当上面选择的是我正在使用的当前代码,但单击步进器时会崩溃,我如何编程步进器以增加标签的值,以及如何获取此值并将其发送到购物车vc以与选项数组中的定价信息相乘,并将所选项目数据发送到购物车中的服务选择单元格,或者在Service1ViewController中将其相乘,并将总数据发送到购物车,同时将所选项目数据发送到服务选择单元格?

我为添加到购物车屏幕做了示例。用户可以增加/减少订单。最初,您必须在
字典中存储默认值。链接用于
UISegmentedControl

情节提要
本身中,设置
UIStepper的
最小值
最大值
步骤

var orderCount = [Int : Int]()
override func viewDidLoad() {
    super.viewDidLoad()

    for i in 0...29  // TotaL number of rows
    {
       orderCount[i] = 1 // DEFAULT order count will be 1
    }
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 30
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! SOTableViewCell
    cell.myStepper.tag = indexPath.row // ADDING TAG
    cell.testLbl.text = String(orderCount[indexPath.row]!) // PASS VALUES TO LABEL
    cell.myStepper.value = Double(orderCount[indexPath.row]!) // PASS VALUES TO STEPPER
    cell.selectionStyle = .none
    return cell
}


//ACTION should be in this ViewController. 
@IBAction func stepperAcn(_ sender: UIStepper) {

    print("sender.value         ", sender.value)
    let getTag : Int = sender.tag

    orderCount[getTag] = Int(sender.value)

    tblVw.reloadData()
}

你在使用故事板吗?是的,init函数是另一个类的狙击手,如果你想让我发布我很乐意做的所有代码,那么Stepper在UITableViewCell中。每个单元格,你必须增加/减少你的顺序。是吗?是的,在表格视图的swift文档中,我有更新UIStepper基本答案。你可以改变它。有了这个,你可以根据你的需要进行定制。我需要解释更多关于UIStepper的操作应该在UIViewController中。与**cell.quantityStepper.addTarget(self,action:#selector(setter:cell.stepperLabel.text),for:.valueChanged)**不同,我修改了帖子以使我的问题可以理解,我感谢您的快速回复,但并非您发布的所有内容都与我的整个问题1相关。cell.stepper=步骤[indexPath.row]。这是什么?2. @iAction func valueChanged(uSender:AnyObject){print(“Method.valueChanged activated”)//更新stepperlabel stepperlabel.text=String(Int(quantityStepper.value))}在UIViewController中执行此操作,而不是在UITableViewCelk中执行此操作我知道我必须在UIViewController中执行此操作,但关于问题的其余部分,比如将该值乘以定价整数(这也是我应该使用double来显示小数的另一个问题)并将数据移动到cartVC