UIDatePicker with default nil value – iOS
我搜索了很多,但没有找到解决方案。谁能帮我找出如何将 UIDatePicker 初始值设置为空文本字段??
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
import UIKit import Alamofire import KVNProgress class EditProfileVC: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate @IBOutlet var birthdayText: UnderLineTextField! @IBOutlet var scrollView: UIScrollView! var photoFlag = -1 let activityView = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge) var singleTonInstance = SingleTon.sharedDataContainer var email ="" override func viewDidLoad() self.birthdayText.text ="" SwiftyPlistManager.shared.getValue(for:"access_token", fromPlistWithName:"AccountDetails") { (result, err) in if err == nil activityView.color = UIColor.blue self.view.addSubview(activityView) self.datePickerView.isHidden = true self.genderTxt.isUserInteractionEnabled = false imagePicker.delegate = self datePicker.addTarget(self, action: #selector(datePickerChanged), for: .valueChanged) self.getProfileDetails() } @objc func savePressed() let dateFormatter = DateFormatter() let appDelegate = UIApplication.shared.delegate as! AppDelegate let urlString = appDelegate.serverUrl +"edit_profile?full_name=//(self.fullNameText.text!)&dob=//(dob)&gender=//(self.genderTxt.text!)&bio_data=//(self.bioText.text!)&location=//(self.locationText.text!)&web_site=//(self.webTextField.text!)&token=//(self.token)" } @objc func datePickerChanged(sender: UIDatePicker) let appDelegate = UIApplication.shared.delegate as! AppDelegate let urlString = appDelegate.serverUrl +"view_profile?token=//(self.token)" } @IBAction func birthdayTapped(_ sender: Any) |
上面的代码是我的整个viewcontroller类代码任何人都可以请你帮我找出解决方案。我将birthdayText的值分配为nil I ViewController但没有用。
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
class ViewController: UIViewController {
private let textField: UITextField = { lazy private var datePicker: UIDatePicker = { lazy private var dateFormatter: DateFormatter = { @objc private func datePickerValueChanged(datePicker: UIDatePicker) { override func viewDidLoad() { let stackView = UIStackView(arrangedSubviews: [textField, datePicker]) view.addSubview(stackView) } |
结果:
更新:
您的问题似乎是您在
我没有在我的 xcode 中尝试这个尝试这个
1
2 3 4 5 6 |
@objc func datePickerChanged(sender: UIDatePicker)
{ let formatter = DateFormatter() formatter.dateFormat ="MMMM dd, YYYY" birthdayText.text ="" } |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/268703.html