简体   繁体   中英

Int is not convertible to 'Range<Int>'

I have a custom UITableViewCell , which contains a UIButton (upVoteButtonPressed) and a 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.

The tag of the label has been set in the tableview controller to be the same as the 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' .

The code below is in my custom UITableViewCell . My goal is to pick out a particular value of the array, convert it to an integer and then add 1 to it. 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. 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. Then when putting the array values into the UITableView use label.text = "(theIntValue)" to convert the int values into strings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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