0

我目前面临一个问题,如果填写了所需的信息,我想使用警卫来启用按钮。在阅读了警卫机制之后,我还不清楚一件事。我如何将 UITextFields 与 UISegmentedControls 结合起来,以便必须填写/选择两者才能激活按钮。

@objc func editingChanged(_ textField:UITextField, sgmntControl: UISegmentedControl) {
        if textField.text?.count == 1 {
            if textField.text?.first == " " {
                textField.text = ""
                return
            }
        }

        guard
            let name = tbxName.text, !name.isEmpty,
            let firstName = tbxFirstname.text, !firstName.isEmpty,
            let phoneNr = tbxPhoneNr.text, !phoneNr.isEmpty,
            let birthDate = tbxBirthdate.text, !birthDate.isEmpty,
            let gender = sgmntGender, !gender.isSelected,
            let street = tbxStreet.text, !street.isEmpty,
            let postalCode = tbxPLZ.text, !postalCode.isEmpty,
            let city = tbxCity.text, !city.isEmpty,
            let country = tbxCountry.text, !country.isEmpty,
            let idNumber = tbxIdNo.text, !idNumber.isEmpty,
            let valueCheck = sgmntValueCheck, !valueCheck.isSelected,
            let drivingSchoolFlyer = sgmntDrivingSchoolFlyer, !drivingSchoolFlyer.isSelected,
            let visionTest = sgmntVisionTest, !visionTest.isSelected,
            let visionHelp = sgmntVisionHelp, !visionHelp.isSelected
        else {
            rbbtnSave!.isEnabled = false
            return
        }
        rbbtnSave!.isEnabled = true
    }

我目前不确定我的方法是否正确,谷歌搜索也没有帮助。我认为像使用文本字段一样使用 UISegmentedControl 是有意义的,因为两者都使用 isSelected 和 isEmpty 检查布尔值。

4

0 回答 0