这是我第一次尝试
Swift或iPhone应用程序,所以不用说,我不知道在这一点上如何做很多事情.
现在我有一个带有文本字段和按钮的视图控制器.我设法找到示例代码几乎完成了我需要的.我想做以下事情:
>当我点击文本字段中有一个UIDatePicker来屏幕.
>设置UIDate选择器仅显示时间 – 不是日期.
>将选定的UIDatePicker时间放在文本框中.
>当我点击按钮时,UIDatePicker会消失.
1到3正在工作.但是,如果再次单击文本字段,我无法弄清楚如何使UIDatePicker消失,并仍然返回到屏幕上.
import UIKit class ViewController: UIViewController { @IBOutlet weak var dateField: UITextField! @IBAction func dateField(sender: UITextField) { var datePickerView : UIDatePicker = UIDatePicker() datePickerView.datePickerMode = UIDatePickerMode.Time sender.inputView = datePickerView datePickerView.addTarget(self,action: Selector("handleDatePicker:"),forControlEvents: UIControlEvents.ValueChanged) } @IBAction func DoneButton(sender: UIButton) { //How to make datepicker disappear??? } func handleDatePicker(sender: UIDatePicker) { var timeFormatter = NSDateFormatter() timeFormatter.dateStyle = .NoStyle timeFormatter.timeStyle = .ShortStyle dateField.text = timeFormatter.stringFromDate(sender.date) } override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view,typically from a nib. } }