gpt4 book ai didi

ios - 如何使用标签文本 (Int) 值编写 if 条件

转载 作者:行者123 更新时间:2023-11-28 11:30:44 25 4
gpt4 key购买 nike

我正在从服务器(响应)获取日期以及我存储在标签中的值,如果使用的叶子应该大于总数,我想使用我希望允许下一个 Viewcontroller 的标签编写一个 if 条件离开,我收到错误

我的情况是“总叶子数”和“已用叶子数”将通过服务器动态显示,如果我们应用 2 天的叶子数将转换为(总叶子数),则数字应该是总共 5 片叶子(总叶子数)” 3"和使用过的叶子标签文本将像这种格式一样替换为 2,它将起作用,如果在这种情况下总叶子数为 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)
}

我的错误是编译错误 Cannot convert value of type 'String?'到预期的参数类型“UIContentSizeCategory”从展开的“字符串”值构造“UIContentSizeCategory”

最佳答案

只是通过将字符串转换为int来比较

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

关于ios - 如何使用标签文本 (Int) 值编写 if 条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56791126/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com