Hi folk,
i m new developer for Eureka. I m trying calculate to totalDuration and set this value with valuesDictionary Item.
But i cannot refresh the form.
I think i need some modification in my code. Can you suggest a method for this issue.
thanks
-ici-
`
//
// EditWorkhourViewController.swift
// Workhour
//
// Created by Ibrahim COBANI on 17/10/2016.
// Copyright © 2016 b1. All rights reserved.
//
import UIKit
import Eureka
class EditWorkhourViewController: FormViewController {
var project: JSON = []
var customer: JSON = []
var projectTask: JSON = []
var workHour: JSON = []
override func viewDidLoad() {
super.viewDidLoad()
form =
Section("Çalışma Tarihi")
<<< DateRow("workDate") {
if let workdate: String = workHour["workDate"].string {
let formatter = DateFormatter()
formatter.dateFormat = "dd-MM-yyyy"
let dtWorkDate: Date = NSCalendar.current.date(byAdding: .hour, value: 26, to: formatter.date(from: workdate)!)!
$0.value = dtWorkDate
}
}
+++ Section("Çalışılan Saat")
<<< IntRow("durationHour"){
$0.value = workHour["durationHour"].int
}
.onChange({ (rowVal) in
self.calcDuration()
})
+++ Section("Çalışılan Dakika")
<<< IntRow("durationMinute"){
$0.value = workHour["durationMinute"].int
}
.onChange({ (rowVal) in
self.calcDuration()
})
+++ Section("Toplam Süre")
<<< DecimalRow("totalDuration"){
$0.value = workHour["totalDuration"].double
//$0.disabled = true
}
+++ Section("Çalışma Şekli")
<<< SegmentedRow<String>("workType") {
$0.options = whWorkType
$0.value = workHour["workType"].string ?? "Remote"
}
+++ Section("Çalışma Tipi")
<<< PushRow<String>("workhourType") {
$0.selectorTitle = "Çalışma Tipi"
$0.options = whWorkhourType
$0.value = workHour["workhourType"].string ?? "Consultancy"
$0.value = $0.value == "" ? "Consultancy": $0.value
}
+++ Section("Faturalanabilir")
<<< SwitchRow("chargeable"){
$0.title = "Faturalanabilir"
$0.value = workHour["chargeable"].bool ?? true
}
+++ Section("Talepte Bulunan")
<<< TextRow("requestedBy") {
$0.placeholder = "Talepte Bulunan"
$0.value = workHour["requestedBy"].string ?? ""
}
+++ Section("Yapılan İşin Tanımı")
<<< TextAreaRow("description") {
$0.placeholder = "Yapılan İşin Tanımı"
$0.value = workHour["description"].string ?? ""
}
}
func calcDuration() {
var valuesDictionary = self.form.values(includeHidden: true)
let durationHour: Double = Double(valuesDictionary["durationHour"] as! Int? ?? 0)
let durationMinute: Double = Double(valuesDictionary["durationMinute"] as! Int? ?? 0)
let totalDuration: Double = (durationHour * 60 + durationMinute) / 60
valuesDictionary["totalDuration"] = totalDuration
print(durationHour)
print(durationMinute)
print(totalDuration)
self.form.setValues(valuesDictionary)
valuesDictionary = self.form.values(includeHidden: true)
print(valuesDictionary)
}
}
`
According to Eureka documentation ..
If the form was already displayed we have to reload the visible rows either by reloading the table view tableView.reloadData() or invoking updateCell() to each visible row.
Seems that in the code you posted you are not reloading the visible rows.
similar to #673
Alternatively, you can also get the "totalDuration" row, set its value and reload it.
let totalDuration: DecimalRow = form.rowBy(tag: "totalDuration")
totalDuration.value = newValue
totalDuration.reload()
Let me know if it works...
Last sample is running very perfect Martin.
Thank you.
Most helpful comment
Alternatively, you can also get the "totalDuration" row, set its value and reload it.
Let me know if it works...