我希望应用程序开头的第一个单元格值和result(green)值相同 这是项目的图片
我正在使用的代码-
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")
}
}
让行:DecimalRow =(formViewController()?. form.rowBy(tag: “ MyRowTag”))! -此代码称为第一个单元格
让row2:DecimalRow =(formViewController()?. form.rowBy(tag: “测试”))! -此代码调用结果单元格(绿色)