代码之家  ›  专栏  ›  技术社区  ›  Purna chandra

如果在Swift 3中未选择CollectionView单元格,如何显示警报?

  •  0
  • Purna chandra  · 技术社区  · 7 年前

    我正在开发医生预约应用程序。我有一个集合视图,其中单元格是时隙。用户可以根据自己喜欢的日期选择时间段。我在集合视图下放置了一个按钮,单击该按钮后,用户移动到下一个viewController。如果用户没有选择任何时间段,我想在单击按钮时显示警报。我试了很多,但没有找到解决办法。提前感谢。。。。 查看我的视图的屏幕截图。希望有人能帮助我。。。。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Rami    7 年前

    按以下步骤进行:

    @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)
                }
    }
    

    祝你的应用好运