我正在从服务器获取日期(响应)和存储在标签中的值,我想使用我想允许下一个Viewcontroller使用的标签编写一个if条件,如果使用的叶子应该大于总叶子,并且我得到了错误
我的条件是“total leaves”和“used leaves”将通过服务器动态提供,如果我们应用将转换为(total leaves)“3”的2天假期(total leaves),则数字应该与total 5 leaves(total leaves)中的数字相同,并且used leaves标签文本将替换为2(total leaves)这样的格式,则它将起作用,如果total leaves为0,则在这种情况下也会出错应显示消息
我的代码是

 if  ((self.totalLeaves.text) > (self.usedLeavesLbl.text)) {
            let alert = UIAlertController(title: "Alert", message: "You Dont have leaves to Apply", preferredStyle: .alert)
            alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
                switch action.style{
                case .default:
                    print("Please Enter Details")

                case .cancel:
                    print("cancel")

                case .destructive:
                    print("destructive")
                }}))
            self.present(alert, animated: true, completion: nil)
        }
     else {
        // Fallback on earlier versions
        let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "ApplyLeavesViewController") as! ApplyLeavesViewController
        self.navigationController?.pushViewController(secondViewController, animated: true)
    }

我的错误是编译错误无法转换'String'类型的值到所需的参数类型“UIContentSizeCategory”
从未包装的“String”值构造“UIContentSizeCategory”

最佳答案

只需将字符串转换为int

 if  (Int(self.totalLeaves.text) == 0 || (Int(self.totalLeaves.text) > Int(self.usedLeavesLbl.text))) {
    ...
    ...
}

09-13 06:43