【发布时间】:2017-03-15 17:16:28
【问题描述】:
我有四个文本字段。一种是全浴,一种是四分之三浴,另一种是半浴,最后一种是四分之一浴。但是我转换成int后,还是报“无法转换int类型的值”的错误,代码如下。
HomeSingleton.sharedInstance3.HomeNumberOfFullBathstext = Int(Double(FullBaths.text!)! * 1.0) + Int(Double(Three_FourthsBaths.text!)! * 0.75) + Int(Double(One_HalfBaths.text!)! * 0.5) + Int(Double(One_fourthBaths.text!)! * 0.25)
【问题讨论】:
-
HomeNumberOfFullBathstext是一个字符串,给它分配一个字符串而不是一个 int。 -
@john 将整个值分配给一个整数变量并获取您的输出,然后分配给 yourHomeSingleton.sharedInstance3.HomeNumberOfFullBathstext = String(your variable)
-
它是一个字符串,因为 HomeNumberOfFullBathstext 是单例中的字符串,最后我会再次调用它并将该文本分配给 uilabel
-
@TusharSharma 你能告诉我怎么做吗
-
Var a: Int = Int(Double(FullBaths.text!)! * 1.0) + Int(Double(Three_FourthsBaths.text!)! * 0.75) + Int(Double(One_HalfBaths.text!) ! * 0.5) + Int(Double(One_fourthBaths.text!)! * 0.25) 之后 -: HomeSingleton.sharedInstance3。 HomeNumberOfFullBathstext = String(a) 。不确定它是否会工作尚未测试。