0

I want the first cell value and the result(green) to be same value at the beginning of the app Here is the image of the project

the code i am using -

import Foundation
import Eureka


final class KalkulationCell: Cell<User>, CellType , UITextFieldDelegate{


   // var vlera = ""

    @IBOutlet var percentageField: UITextField!
    @IBOutlet var valueField: UITextField!

    required init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override func setup() {
        super.setup()
        // we do not want our cell to be selected in this case. If you use such a cell in a list then you might want to change this.
        percentageField.delegate = self
        selectionStyle = .none


        //        percentageField.text = "25.00"
        // define fonts for our labels
        percentageField.font = .systemFont(ofSize: 18)
        valueField.font = UIFont.boldSystemFont(ofSize: 18.0)

        percentageField.textColor=UIColor.black
        // percentageField.font = UIFont.boldSystemFont(ofSize: 18.0)
        // specify the desired height for our cell
        //height = { return 94 }

        // set a light background color for our cell
        // backgroundColor = UIColor(red:0.984, green:0.988, blue:0.976, alpha:1.00)
    }

    override func update() {
        super.update()


        // get the value from our row

        guard let user = row.value else { return }
        //
        percentageField.text = user.percentage.description
        valueField.text = user.value.description
    }



    func textFieldDidEndEditing(_ textField: UITextField) {

calculate()

    }
    func calculate(){

        let row: DecimalRow = (formViewController()?.form.rowBy(tag: "MyRowTag"))!
        let row2: DecimalRow = (formViewController()?.form.rowBy(tag: "test"))!

        var perqindja = Double(percentageField.text!)
        var vlera = Double(valueField.text!)
            if let vlera1 = row.value{

                if perqindja != nil {

                    let kosto = (row.value)!*perqindja!*0.01
                    valueField.text  = kosto.description
                    let exclamationMark: Character = "%"
                    percentageField.text?.append(exclamationMark)
                    valueField.isUserInteractionEnabled = false
                    valueField.reloadInputViews()
                }else if vlera != nil {
                    // perqindja = Double(percentageField.text!)
                    let kosto1 = round((vlera!/(row.value)!)*100)

                    percentageField.text  = kosto1.description
                    let exclamationMark: Character = "%"
                    percentageField.text?.append(exclamationMark)
                    percentageField.isUserInteractionEnabled = false
                     percentageField.reloadInputViews()
                }
            }
            else{
            }
    }

    func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {

        if let text = textField.text,
            !text.isEmpty {
            textField.text?.removeLast()
            //valueField.text?.removeAll()
        }
calculate()

        return formViewController()?.textInputShouldBeginEditing(textField, cell: self) ?? true
    }

}


struct User: Equatable {

    var percentage: String
    var value: String

}
func ==(lhs: User, rhs: User) -> Bool {
    return lhs.percentage == rhs.percentage
}


final class KalkulationRow: Row<KalkulationCell>, RowType {
    required init(tag: String?) {
        super.init(tag: tag)
        cellProvider = CellProvider<KalkulationCell>(nibName: "KalkulationCell")
    }
}

let row: DecimalRow = (formViewController()?.form.rowBy(tag: "MyRowTag"))! --This code call first cell

let row2: DecimalRow = (formViewController()?.form.rowBy(tag: "test"))! --This code call result cell(green)

Kdr
  • 13
  • 7
  • I want the first cell value and the result(green) to be same means what you required exactly... Are you want color or value which one – Naresh Jul 13 '18 at 08:45
  • @iOS i want to be tha same value – Kdr Jul 13 '18 at 12:19
  • Hai, which parameter you are passing to result cell, send same parameter value to first cell – Naresh Jul 13 '18 at 12:22
  • Actually you need to post related table view code, because the logic is there in table view delegates... – Naresh Jul 13 '18 at 12:23
  • @IOS i update the code , you can see now. thanks for your help – Kdr Jul 13 '18 at 12:38
  • Hay, When you get the result value(54.00) at time of app opening or at the time of after getting. When? Same as first cell value also when? – Naresh Jul 13 '18 at 12:43
  • Here you are using UITableView. If you want to update table view cell data you need to use yourTableView.reloadData() or use reloadRows function https://stackoverflow.com/questions/4448321/is-it-possible-to-refresh-a-single-uitableviewcell-in-a-uitableview – Naresh Jul 13 '18 at 12:51
  • With out reloadTableView or update row you con't update the " UITablewViewCell components data" – Naresh Jul 13 '18 at 12:52
  • @iOS thanks for your help – Kdr Jul 16 '18 at 07:22

0 Answers0