class Service1ViewController: UIViewController {
@IBOutlet weak var service1TableView: UITableView!
@IBOutlet weak var service1Total: UILabel!
var Dry: [Service1] = []
var orderCount = [Int : Int]()
override func viewDidLoad() {
super.viewDidLoad()
Dry = Options()
for i in 0...30 // TotaL number of rows
{
orderCount[i] = 0 // DEFAULT order count will be 0
}
}
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{
@IBAction func stepperAcn(_ sender: UIStepper) {
print("sender.value ", sender.value)
let getTag : Int = sender.tag
orderCount[getTag] = Int(sender.value)
service1TableView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 31
}
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.quantityStepper.tag = indexPath.row
cell.stepperLabel.text = String(orderCount[indexPath.row]!) // PASS VALUES TO LABEL
cell.quantityStepper.value = Double(orderCount[indexPath.row]!) // PASS VALUES TO STEPPER
cell.selectionStyle = .none
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
func Total(){
let cell = tableView.cellForRow(at: indexPath.row)
service1Total.text = cell.stepperLabel.value
}
}
}
我想从所有单元格的步进器标签的更新值中获取数据,并将其乘以特定单元格定价(位于函数Options()中)并将结果打印到service1Total。然后在函数准备seague我希望步进器标签值大于0的单元格将数据移动到另一个viewController中的备用tableViewCell以及移动总数据。这是当前的代码,但我无法弄清楚如何让它工作。