change the date with swift

Asked 2 years ago, Updated 2 years ago, 87 views

I would like to create an application to change the date, but I get an error (signal SIGABRT) in the code below.
I'm sorry to trouble you, but could you give me some advice?

import UIKit

classViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITextFieldDelegate{

    @IBOutlet weak var Picture 1: UIButton!
    @IBOutlet weak var Pictureimage1: UIImageView!
    @IBOutlet weak var Date: UILabel!
    @IBOutlet weak var Name: UILabel!
    @IBOutlet weak var WO: UILabel!
    @IBOutlet weak var Card: UILabel!
    @IBOutlet weak var SelectDate: UITextField!
    @IBOutlet weak var text1: UITextField!
    @IBOutlet weak var text2: UITextField!
    @IBOutlet weak var text3: UITextField!
    @IBOutlet weak varbut:UIButton!
    @IBOutlet weak var sub:UILabel!

    let nowDate=NSDate()
    let dateFormat = DateFormatter()
    let inputDatePicker=UIDatePicker()

    override func viewDidLoad(){
        super.viewDidLoad()

        dateFormat.dateFormat="yyyy/MM/dd"
        self.SelectDate.text=dateFormat.string (from: nowDate as Date)
        self.SelectDate.delegate=self

        inputDatePicker.datePickerMode=UIDatePickerMode.date
        self.SelectDate.inputView=inputDatePicker

        letpickerToolBar=UIToolbar(frame:CGRect(x:0,y:self.view.frame.size.height/6,width:self.view.frame.size.width,height:40.0))
        pickerToolBar.layer.position = CGPoint (x:self.view.frame.size.width/2, y:self.view.frame.size.height-20.0)
        pickerToolBar.barStyle=.blackTranslucent
        pickerToolBar.tintColor=UIColor.white
        pickerToolBar.backgroundColor=UIColor.black

        letspaceBarBtn = UIBarButtonItem(barButtonSystemItem:UIBarButtonSystemItem.flexibleSpace, target:self, action:Selector(("a:"))

        let toolBarBtn = UIBarButtonItem(title: "OK", style: .done, target:self, action:Selector(("toolBarBtnPush:"))

        pickerToolBar.items=[spaceBarBtn, toolBarBtn]
        self.SelectDate.inputAccessoryView=pickerToolBar
    }

        US>func toolBarBtnPush (sender: UIBarButtonItem) {
            letpickerDate=inputDatePicker.date
            self.SelectDate.text=dateFormat.string (from:pickerDate as Date)

            self.view.endEditing(true)
        }
}

swift swift3

2022-09-30 19:53

1 Answers

The format of the selector has changed since Swift3.

let toolBarBtn=UIBarButtonItem(title: "OK",
    style:.done,
    target —self,
    action:Selector(("toolBarBtnPush:"))

Not only the format, but also one set of parentheses is added.

The Selector("toolBarBtnPush:") in this line changes as follows:

#selector(ViewController.toolBarBtnPush(sender:))

You can omit ViewController. when you specify it in the ViewController class.(It is recommended that you specify which class the action method is defined for, so you have the class name on your head.)

*Regardless of the subject, the model name NSDate has been changed from Swift3 to Date, so it would be more refreshing to unify. asDate casts are not required.


2022-09-30 19:53

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.