作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在从 API 中以字符串数组的形式获取评级数据。但“RatingControl.Rating”值只接受 Int 值。因此,当在自定义表格 View 单元格中填充评级时,它会给出错误。如何解决?
评级声明:
var Ratings:Array< String > = Array < String >()
现在我从 Api 获取数据:
var json: NSArray!
do {
json = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions()) as? NSArray
} catch {
print(error)
}
self.Ratings = json.valueForKey("rate") as! Array<String>
print(self.Ratings)
它成功地向我展示了 Api 的值(value)。现在我将其填充到自定义 TableView 单元中。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell =
tableView.dequeueReusableCellWithIdentifier("ReviewCustomCell",
forIndexPath: indexPath) as! ReviewCustomCell
**cell.ratingControl.rating = Ratings[indexPath.row]**
return cell
}
上面的粗体显示错误为“无法接受字符串类型的值到 int”。任何人都可以提出解决这个问题的想法。
最佳答案
让我们尝试将评级值作为整数数组而不是字符串数组。
// var Ratings:Array< String > = Array < String >()
var Ratings:Array<Int > = Array<Int >()
检查是否有效
关于swift - 如何在 swift 中接受 RateController 的评级值作为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37752123/
我正在从 API 中以字符串数组的形式获取评级数据。但“RatingControl.Rating”值只接受 Int 值。因此,当在自定义表格 View 单元格中填充评级时,它会给出错误。如何解决? 评
我是一名优秀的程序员,十分优秀!