0

I am working on a Doctor Appointment App. I have a collection view in which cells are time slots. User can select time slot based on date of his favour.I placed a button under the collection view and after clicking that button user moves to next viewController. I want to show alert on clicking a button if user doesn't select any time slot. I tried a lot but not finding a solution. Thanks in advance.... check the screenshot of my view. Hoping someone would help me....

Purna chandra
  • 107
  • 10
  • add some code snippet what you have tried. – Warewolf Nov 02 '17 at 06:19
  • sorry, I tried finding a solution for that not in terms of coding... – Purna chandra Nov 02 '17 at 06:41
  • I am not getting an idea how to implement that...once knowing that idea I can implement that.. – Purna chandra Nov 02 '17 at 06:42
  • have you implemented collection view (https://stackoverflow.com/a/26837134/1305001) – Warewolf Nov 02 '17 at 06:46
  • you need to apply check in array (that you will use to display data in collectionView) using loop. If none of the element is selected then show alert otherwise proceed. – Warewolf Nov 02 '17 at 06:48
  • Yeah I implemented collection view. I am controlling collection view data with two buttons, left arrow button and right arrow button. Between those two buttons I placed a label and displaying date on that. when user clicking on those arrow buttons date will be changed and collection view below that label will be reloaded displaying time slots. I am displaying time slots using a dictionary which contain times and their status. I didn't understood how to apply check. can u please elaborate – Purna chandra Nov 02 '17 at 06:56
  • Thanks for your reply.... – Purna chandra Nov 02 '17 at 06:56
  • `create an empty array -> then inside did select method add or remove elements to that array -> then when you click on that button check your array and show your alert` – Chanaka Anuradh Caldera Nov 02 '17 at 07:02
  • In dictionary add additional key named selected of type bool. Default value will be 0 whenever user selects set its value to 1 that will indicate as selected. – Warewolf Nov 02 '17 at 07:03
  • thanks both of u... I ll implement – Purna chandra Nov 02 '17 at 07:50
  • I implemented the functionality... thanks a lot both of u for the help – Purna chandra Nov 02 '17 at 08:07

1 Answers1

1

proceed as following:

@IBAction func buttonPressed(_ sender: Any) {
            if timeSlotsCollectionView.indexPathsForSelectedItems == [] {
                let alert = UIAlertController(title: "DID NOT SELECT A TIME SLOT", message: "Please select a time slot!", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
                self.present(alert, animated: true, completion: nil)
            }
}

Good luck with your App

Rami
  • 194
  • 1
  • 4