首页 > 解决方案 > Uitextfield通知xcode 12

问题描述

uitextfield如何出现消息必须先填写才能执行?我已经搜索了谷歌,但找不到它。

我的设计

标签: swiftxcode12

解决方案


您的意思是显示一条消息说在前进之前必须填写文本字段吗?如果是这样,请在每个 textField 上使用 if 语句

if namaField.text == "" || alamatField.text == "" || phoneField.text == "" {
    let alertController = UIALertController(title: "Enter all fields", preferredStyle: .alert)
    let okayAction = UIAlertAction(title: "Okay", style: .default, handler: { action in
        self.dismiss(animated: true, completion: nil)
    })
    alert.addAction(okayAction)
    self.present(alert, animated: true)
}

推荐阅读