ViewController2中的UiTextField更改Struct Var的值

时间:2015-07-26 23:03:18

标签: ios objective-c iphone swift struct

我有两个视图控制器与tabBar连接。在第一个选项卡中,我看到所有按钮都添加了修复和删除修复。在我的私有项目的第一步中,我有修复时间的静态值。现在在我的第二步中,我想要通过第二次点击来改变一个人需要修复的时间,但是当我在第二个VieController中编辑时间后返回时,结构的值没有改变。

ViewController.swift 

class ViewController: UIViewController {

@IBOutlet weak var AddBrepair: UIButton!
@IBOutlet weak var AddOrepair: UIButton!
@IBOutlet weak var AddDrepair: UIButton!
@IBOutlet weak var GeniusNumber: UISegmentedControl!
@IBOutlet weak var AddBCrepair: UIButton!
@IBOutlet weak var CheckOutOrepair: UIButton!
@IBOutlet weak var CheckOutBrepair: UIButton!
@IBOutlet weak var CheckOutBCrepair: UIButton!
@IBOutlet weak var CheckOutDrepair: UIButton!
@IBOutlet weak var DisplayLeftNumber: UILabel!
@IBOutlet weak var RFPTime: UILabel!
@IBOutlet weak var CurrentTimerepair: UILabel!
let repairTime=RepairTime()


override func viewDidLoad() {
    super.viewDidLoad()
    //RFPTime.text = repairTime.ReadyForPickup()

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    //print(repairTime.getNumberOfRepairGenius())

}




@IBAction func Controller(sender: AnyObject) {

    repairTime.NumberOfRepairGenius(GeniusNumber.selectedSegmentIndex+1)
    CurrentTimerepair.text = String(format:"%.1f", repairTime.TimeOfRepair())
    RFPTime.text = String(repairTime.ReadyForPickup())
}

@IBAction func AddBr(sender: AnyObject) {

    repairTime.NumberOfBatteryRepair(repairTime.getNumberOfBatteryRepair()+1)
    CurrentTimerepair.text = String(format:"%.1f", repairTime.TimeOfRepair())
    RFPTime.text = String(repairTime.ReadyForPickup())

}

@IBAction func AddOr(sender: AnyObject) {

    repairTime.NumberOfOtherRepair(repairTime.getNumberOfOtherRepair()+1)
    CurrentTimerepair.text = String(format:"%.1f", repairTime.TimeOfRepair())
    RFPTime.text = String(repairTime.ReadyForPickup())

}

@IBAction func AddBCr(sender: AnyObject) {

repairTime.NumberOfBackCoverRepair(repairTime.getNumberOfBackCoverRepair()+1)
    CurrentTimerepair.text = String(format:"%.1f", repairTime.TimeOfRepair())
    RFPTime.text = String(repairTime.ReadyForPickup())

}

@IBAction func AddDr(sender: AnyObject) {

    repairTime.NumberOfDisplayRepair(repairTime.getNumberOfDisplayRepair()+1)
    CurrentTimerepair.text = String(format:"%.1f", repairTime.TimeOfRepair())
    RFPTime.text = String(repairTime.ReadyForPickup())

    //print("view controler")
    //print(

}

@IBAction func DeleteBr(sender: AnyObject) {
    if(repairTime.getNumberOfBatteryRepair() != 0){
    repairTime.NumberOfBatteryRepair(repairTime.getNumberOfBatteryRepair()-1)
    CurrentTimerepair.text = String(format:"%.1f", repairTime.TimeOfRepair())
        RFPTime.text = String(repairTime.ReadyForPickup())
    }

}
@IBAction func DeleteOr(sender: AnyObject) {
    if(repairTime.getNumberOfOtherRepair() != 0){
    repairTime.NumberOfOtherRepair(repairTime.getNumberOfOtherRepair()-1)
    CurrentTimerepair.text = String(format:"%.1f", repairTime.TimeOfRepair())
        RFPTime.text = String(repairTime.ReadyForPickup())
    }
}

@IBAction func DeleteBCr(sender: AnyObject) {
    if(repairTime.getNumberOfBackCoverRepair() != 0){

repairTime.NumberOfBackCoverRepair(repairTime.getNumberOfBackCoverRepair()-1)
    CurrentTimerepair.text = String(format:"%.1f", repairTime.TimeOfRepair())
        RFPTime.text = String(repairTime.ReadyForPickup())
    }
}
@IBAction func DeleteDr(sender: AnyObject) {
    if(repairTime.getNumberOfDisplayRepair() != 0){
    repairTime.NumberOfDisplayRepair(repairTime.getNumberOfDisplayRepair()-1)
    CurrentTimerepair.text = String(format:"%.1f", repairTime.TimeOfRepair())
        RFPTime.text = String(repairTime.ReadyForPickup())
    }
}

@IBAction func ShowQueuePop(sender: AnyObject) {
    let out="Display Repair: \(repairTime.getNumberOfDisplayRepair()) \n Other Repair: \(repairTime.getNumberOfOtherRepair()) \n Battery Repair: \(repairTime.getNumberOfBatteryRepair()) \n Back Cover Repair: \(repairTime.getNumberOfBackCoverRepair())"

    let alertController = UIAlertController(title: "Current repair Queue", message: out
        , preferredStyle: UIAlertControllerStyle.Alert)
    alertController.addAction(UIAlertAction(title: "Dismiss", style: UIAlertActionStyle.Default,handler: nil))

    self.presentViewController(alertController, animated: true, completion: nil)
}



class RepairTime {

var optiontime = OptionTime()
var RepairGenius: Int = 1
var DisplayRepair: Int = 0
var OtherRepair: Int = 0
var BackCoverRepair: Int = 0
var BatteryRepair: Int = 0

func TimeOfRepair()->Double{
        var repairtimezwei: Double
        repairtimezwei=0.0
        var repairzeit: Int
        repairzeit=0
        repairzeit=(BatteryRepair*optiontime.BatteryTime)+(BackCoverRepair*optiontime.BCTime)+(DisplayRepair*optiontime.DisplayTime)+(OtherRepair*optiontime.OtherTime)
        //print(DisplayRepair)
        repairtimezwei = (Double(repairzeit)/Double(RepairGenius))+15.0



        return repairtimezwei
    }

所以这是我的第二个viewController:

class ViewController2: UIViewController,UITextFieldDelegate {

var optiontime = OptionTime()



@IBOutlet weak var DisplayTime: UITextField!

@IBOutlet weak var BatteryTime: UITextField!

@IBOutlet weak var BackCoverTime: UITextField!

@IBOutlet weak var OtherTime: UITextField!


override func viewDidLoad() {
    super.viewDidLoad()
    //RFPTime.text = repairTime.ReadyForPickup()

    // set TextField with Values of struct optionTime from class RepairTime
   DisplayTime.text=String(optiontime.DisplayTime)
    BatteryTime.text=String(optiontime.BatteryTime)
    BackCoverTime.text=String(optiontime.BCTime)
    OtherTime.text=String(optiontime.OtherTime)


    //set KeybardType for Textinputs 
    self.DisplayTime.keyboardType = UIKeyboardType.NumbersAndPunctuation
    self.BatteryTime.keyboardType = UIKeyboardType.NumbersAndPunctuation
    self.BackCoverTime.keyboardType = UIKeyboardType.NumbersAndPunctuation
    self.OtherTime.keyboardType = UIKeyboardType.NumbersAndPunctuation

    self.DisplayTime.delegate = self
   self.BatteryTime.delegate = self
   self.BackCoverTime.delegate = self
    self.OtherTime.delegate = self

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()

}

func textFieldShouldReturn(textField: UITextField) -> Bool {
    self.view.endEditing(true)
    return false
}


@IBAction func TimeChangeDisplay(sender: AnyObject) {

    optiontime.DisplayTime = Int(DisplayTime.text!)!
print("vie controler 2")
    print(optiontime.DisplayTime)


}


@IBAction func TimeChangeBattery(sender: AnyObject) {
   optiontime.BatteryTime = Int(BatteryTime.text!)!
}


@IBAction func TimeChangeBC(sender: AnyObject) {
        optiontime.BCTime = Int(BackCoverTime.text!)!
}


@IBAction func TimeChangeOther(sender: AnyObject) {
    optiontime.OtherTime = Int(OtherTime.text!)!
}


}

我的问题是在文本字段中完成编辑后结构的值没有改变。

0 个答案:

没有答案