0

I found a calendarDatePicker here and I want to show that custom picker when user touched textField.

In my previous project I just created a default pickerView and then set it to textField's inputView and it works.

And here I've tried to do this again but THCalendarDatePicker is a viewController, not an inputView.

Here is the code:

class ViewController: UIViewController, THDatePickerDelegate {

@IBOutlet weak var textField: UITextField!

var datePicker:THDatePickerViewController?
var curDate: NSDate?

override func viewDidLoad() {
    super.viewDidLoad()
    self.curDate = NSDate()

    datePicker = THDatePickerViewController.datePicker()
    datePicker!.delegate = self
    datePicker!.setAllowClearDate(false)
    datePicker!.setClearAsToday(true)
    datePicker!.setAutoCloseOnSelectDate(false)
    datePicker!.setAllowSelectionOfSelectedDate(true)
    datePicker!.setDisableHistorySelection(false)
    datePicker!.setDisableFutureSelection(false)
    //datePicker!.autoCloseCancelDelay = 5.0
    datePicker!.selectedBackgroundColor = UIColor.blackColor()
    datePicker!.currentDateColor = UIColor.yellowColor()
    datePicker!.currentDateColorSelected = UIColor.yellowColor()
}

@IBAction func touchInInput(sender: AnyObject) {
    datePicker!.date = curDate
    datePicker!.setDateHasItemsCallback({(date:NSDate!) -> Bool in
        let tmp = (arc4random() % 30) + 1
        return tmp % 5 == 0
    })
    presentSemiViewController(datePicker!, withOptions: [
        KNSemiModalOptionKeys.pushParentBack    : NSNumber(bool: true),
        KNSemiModalOptionKeys.animationDuration : NSNumber(float: 0.5),
        KNSemiModalOptionKeys.shadowOpacity     : NSNumber(float: 0.3)
    ])

    sender.inputView == ??? // what I should code here?
}

func datePickerCancelPressed(datePicker: THDatePickerViewController!) {
    self.dismissSemiModalView()
}

func datePickerDonePressed(datePicker: THDatePickerViewController!) {
    self.dismissSemiModalView()
}

func datePicker(datePicker: THDatePickerViewController!, selectedDate: NSDate!) {
    println(selectedDate)
}
}

Can someone help me?

user3182143
  • 9,459
  • 3
  • 32
  • 39
mkz
  • 2,302
  • 2
  • 30
  • 43

2 Answers2

0

My suggestions would be to

1 programmatically create a container view, populate the container with the view controller, and then try to add that as the inputView for your keyboard.

I have my doubts that would work but it's certainly wouldn't hurt to try.

2 perhaps reconsider your design (if it's your call) and use a pop over view instead that contains your date picker.

Either way let me know how it works out.

Brandon A
  • 8,153
  • 3
  • 42
  • 77
0

Cant you set the datePicker.view value as input view

Sujith Chandran
  • 2,671
  • 1
  • 15
  • 13