简体   繁体   English

Int不可转换为&#39;Range <Int> “

[英]Int is not convertible to 'Range<Int>'

I have a custom UITableViewCell , which contains a UIButton (upVoteButtonPressed) and a UILabel (voteScoreLabel). 我有一个自定义UITableViewCell ,其中包含一个UIButton (upVoteButtonPressed)和一个UILabel (voteScoreLabel)。

In order to get the numerical scores to show up in the labels of the UITableView, the array that contains that the number of votes is a String array, although its contents are in actuality integers. 为了使数值得分显示在UITableView的标签中,包含投票数的数组是String数组,尽管其内容实际上是整数。

The tag of the label has been set in the tableview controller to be the same as the indexPath.row . 标签的标签已在tableview控制器中设置为与indexPath.row相同。 This lets me pick a particular item in the array. 这使我可以选择数组中的特定项目。

However when I want to add a specific value, add 1 for example, I cannot because when I try to execute the following code I get the following error: Int is not convertible to 'Range' . 但是,当我想添加一个特定的值时,例如添加1,我不能,因为当我尝试执行以下代码时,出现以下错误: Int is not convertible to 'Range'

The code below is in my custom UITableViewCell . 下面的代码在我的自定义UITableViewCell My goal is to pick out a particular value of the array, convert it to an integer and then add 1 to it. 我的目标是挑选出数组的特定值,将其转换为整数,然后再添加1。 What does this mean and how can I fix it. 这是什么意思,我该如何解决。

@IBAction func upVoteButtonPressed(sender: AnyObject) {
    groupVote[voteScoreLabel.tag]=groupVote[voteScoreLabel.tag].toInt()
}

Edit 编辑
The solution suggested in the comments to make the array type int, and then when putting into the tableview to convert to string has worked. 注释中建议的解决方案使数组类型为int,然后在将其放入表视图以转换为字符串时起作用。 Problem Solved. 问题解决了。

Make the array type an int because the array is currently seen as a String type array and that is backwards and inefficient. 将数组类型设置为int,因为该数组当前被视为String类型的数组,并且该数组向后且效率低下。 Then when putting the array values into the UITableView use label.text = "(theIntValue)" to convert the int values into strings. 然后,将数组值放入UITableView使用label.text =“(theIntValue)”将int值转换为字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM