我有一个DatePicker,用户选择时间和日期字段,键盘首先显示,然后我必须再次单击文本字段才能显示Picker。我想要的是DatePicker在第一次尝试时出现。
这是我的代码
@IBOutlet var dateField: UITextField! = UITextField()
@IBOutlet var timeField: UITextField! = UITextField()
@IBAction func userPickDate(sender: UITextField) {
var datePickerView : UIDatePicker = UIDatePicker()
datePickerView.datePickerMode = UIDatePickerMode.Date
sender.inputView = datePickerView
datePickerView.addTarget(self, action: Selector("handleDatePicker:"), forControlEvents: UIControlEvents.ValueChanged)
}
@IBAction func userPickTime(sender: UITextField) {
var datePickerView : UIDatePicker = UIDatePicker()
datePickerView.datePickerMode = UIDatePickerMode.Time
sender.inputView = datePickerView
datePickerView.addTarget(self, action: Selector("handleTimePicker:"), forControlEvents: UIControlEvents.ValueChanged)
}
func handleTimePicker(sender: UIDatePicker)
{
var timeFormatter = NSDateFormatter()
timeFormatter.timeStyle = .ShortStyle
timeField.text = timeFormatter.stringFromDate(sender.date)
}
func handleDatePicker(sender: UIDatePicker) {
var timeFormatter = NSDateFormatter()
timeFormatter.dateStyle = .MediumStyle
//timeFormatter.timeStyle = .ShortStyle
dateField.text = timeFormatter.stringFromDate(sender.date)
}
答案 0 :(得分:1)
弃掉最后一个答案。我明白你在做什么。这是我发现的:将UPickerView对象的声明放在类的范围而不是本地化到处理程序似乎工作。这是代码。请注意添加resignFirstResponder()。
import UIKit
class ViewController: UIViewController {
var datePickerView : UIDatePicker = UIDatePicker()
var timePickerView : UIDatePicker = UIDatePicker()
@IBOutlet weak var dateField: UITextField!
@IBOutlet weak var timeField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
datePickerView.datePickerMode = UIDatePickerMode.Date
dateField.inputView = datePickerView
datePickerView.addTarget(self, action: Selector("handleDatePicker:"), forControlEvents: UIControlEvents.ValueChanged)
handleDatePicker(datePickerView)
timePickerView.datePickerMode = UIDatePickerMode.Time
timeField.inputView = timePickerView
timePickerView.addTarget(self, action: Selector("handleTimePicker:"), forControlEvents: UIControlEvents.ValueChanged)
handleTimePicker(timePickerView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func handleDatePicker(sender: UIDatePicker) {
var dateFormatter = NSDateFormatter()
dateFormatter.dateStyle = .MediumStyle
//timeFormatter.timeStyle = .ShortStyle
dateField.text = dateFormatter.stringFromDate(sender.date)
dateField.resignFirstResponder()
}
func handleTimePicker(sender: UIDatePicker) {
var timeFormatter = NSDateFormatter()
timeFormatter.timeStyle = .ShortStyle
timeField.text = timeFormatter.stringFromDate(sender.date)
timeField.resignFirstResponder()
}
}
答案 1 :(得分:0)
您需要在textField上执行操作:
import java.io.IOException;
import java.util.ArrayList;
public class SyntaxAnalyzer {
public static int pos = 0;
public static ArrayList<String> lexems = new ArrayList<String>();
public static ArrayList<String> tokens = new ArrayList<String>();
public static String nextToken;
public static void main(String[] args) throws IOException {
LexicalAnalysis lex = new LexicalAnalysis();
lex.getFile();
lex.parseText();
ArrayList<String> lexems = lex.getLexems();
lex.printList(lexems);
ArrayList<String> tokens = lex.getTokens();
lex.printList(tokens);
//expr();
lex();
}
static void lex(){
//String lexem = lexems.get(pos);
//System.out.println(lexem);
nextToken = tokens.get(pos);
pos++;
}
}
答案 2 :(得分:0)
这是Syed对Swift 2.2&amp;的回答的更新版本。包括一些格式更新。
$tid = $node->field_category->target_id;