I'm developing an app where user should able to choose a time slot. i.e 8:00 AM - 8: 30 AM or 2:00 PM - 2: 30 PM. But I want the user to choose only the time slot based on current time. i.e if its 8PM, he shouldn't able to choose slots till 9PM. I need minimum an hour gap. For now I have just hard coded the time slots as shown below and displaying in a picker view.
var items = ["8.00 AM - 8.30 AM","8.30 AM - 9.00 AM","9.00 AM - 9.30 AM","9.30 AM - 10.00 AM","10.00 AM - 10.30 AM","10.30 AM - 11.00 AM","11.00 AM - 11.30 AM","11.30 AM - 12.00 PM","12.00 PM - 12.30 PM","12.30 PM - 1.00 PM","1.00 PM - 1.30 PM","1.30 PM - 2.00 PM","2.00 PM - 2.30 PM","2.30 PM- 3.00 PM","3.00 PM - 3.30 PM","3.30 PM - 4.00 PM","4.00 PM - 4.30 PM","4.30 PM - 5.00 PM","5.00 PM - 5.30 PM","5.30 PM - 6.00 PM","6.00 PM - 6.30 PM","6.30 PM - 7.00 PM","7.00 PM - 7.30 PM","7.30 PM - 8.00 PM","8.00 PM - 8.30 PM","8.30 PM - 9.00 PM"]
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if pickerView.tag == 1 {
return dates[row] as? String
}else{
return items[row]
}
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if pickerView.tag == 1 {
dateTextField.text = dates[row] as? String
}else if pickerView.tag == 2{
timeTextField.text = items[row]
}
When the user selects the time and if it has past, I want to present an alert or I should disable the time slots which has past. Could anyone please help me to achieve this.