2014-09-11 65 views
2

是否有任何方法來顯示UIAlertControllerStyle.ActionSheet中的日期選擇器?有辦法添加按鈕和添加動作到ActionSheet中的這些按鈕,但我找不到在ActionSheet中添加日期選擇器或任何自定義視圖的解決方案。使用Swift在UIActionsheet中添加日期選擇器

回答

9

這是不可能的,但你可以使用的UITextField輸入視圖和附屬視圖顯示,當用戶點擊文本框

class KPDatePickerViewController: UIViewController { 
    var datePicker:UIDatePicker! 
    @IBOutlet var dateTextField:UITextField! 

    override func viewDidLoad() { 
     var customView:UIView = UIView (frame: CGRectMake(0, 100, 320, 160)) 
     customView.backgroundColor = UIColor.brownColor() 
     datePicker = UIDatePicker(frame: CGRectMake(0, 0, 320, 160)) 
     customView .addSubview(datePicker) 
     dateTextField.inputView = customView 
     var doneButton:UIButton = UIButton (frame: CGRectMake(100, 100, 100, 44)) 
     doneButton.setTitle("Done", forState: UIControlState.Normal) 
     doneButton.addTarget(self, action: "datePickerSelected", forControlEvents: UIControlEvents.TouchUpInside) 
     doneButton.backgroundColor = UIColor .blueColor() 
     dateTextField.inputAccessoryView = doneButton 
    } 

    func datePickerSelected() { 
     dateTextField.text = datePicker.date.description 
    } 
} 
+0

謝謝KARTHIK我想同樣的事情,駁回日期選擇器,但不知道如何駁回這個觀點! – Vijay 2014-09-16 05:56:46

+0

我用resignFirstResponder()解僱它,它工作得很好:) – Vijay 2014-09-16 06:28:20

相關問題