gpt4 book ai didi

ios - 如何同时保存索引值和评级值?

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

这里我使用了HCSStarRatingview进行评级,在这里我在表格 View 中实现了它,这样我需要获取所选的特定评级值并需要根据其索引进行保存,并且应该还有稍后还需要更改保存的值,并且需要插入选定的索引,任何人都可以帮助我如何实现这一点?

这是我的代码

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "ratingCell", for: indexPath) as! ratingCell
return cell
}
else if indexPath.section == 1 {
let cell = tableView.dequeueReusableCell(withIdentifier: "reviewCell", for: indexPath) as! AddaReviewTableViewCell
let arr = reviewModel[indexPath.row]
cell.reviewTypeLabel.text = arr.ratingCode
cell.starRatingControl.tag = indexPath.row
cell.starRatingControl.addTarget(self, action: #selector(RatingControlAction(_:)), for: .touchUpInside)
return cell
}
else{
let cell = tableView.dequeueReusableCell(withIdentifier: "reviewInputCell", for: indexPath) as! reviewInputCell
nickName = cell.nameTextField.text
summary = cell.summaryTextField.text
review = cell.reviewTextView.text
cell.submitReviewButton.addTarget(self, action: #selector(submitReviewAction(_:)), for: .touchUpInside)
return cell
}
}
func isValidFirstname(testStr:String) -> Bool {
let firstnameRegEx = "^[a-zA-Z]+$"
let firstnameTest = NSPredicate(format:"SELF MATCHES %@", firstnameRegEx)
let result = firstnameTest.evaluate(with: testStr)
return result
}
func RatingControlAction(_ sender:Any){
let buttonPosition = (sender as AnyObject).convert(CGPoint(), to: tableDetails)
let index = tableDetails.indexPathForRow(at: buttonPosition)
print(String(format: "Changed rating to %.1f", (sender as AnyObject as! CVarArg)))
}

此处显示了此屏幕截图

enter image description here

最佳答案

为什么不创建一个可以容纳两个值的结构

声明一个结构体

struct Struct_Row_Rating {
var row: String
var rating: Int

init(row: String , rating: Int ) {
self.row = row
self.rating = rating

}}

声明一个数组

     var arrayAdaptor  = [Struct_Row_Rating]()

像这样附加数组

  arrayAdaptor.append(Struct_Row_Rating(row: IndexPath.row, rating: 3)

您可以通过以下方式检索值

var index1 = arrayAdaptor[1].rating // use dynamic value here

More on struct

关于ios - 如何同时保存索引值和评级值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46906747/

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