如何在每个TableViewCell中保存唯一的分数?
我想将分数保存在我用领域保存的单元格中。
这是我程序的图像。
当我按下左上角按钮时,警报弹出以添加带有标签的新单元格。该单元格由领域保存并正确显示。然后,在单元格上,每侧都有两个按钮,可以将数字添加或减在单元格下的分数中。
现在,当我更改每个单元格时,我也想保存分数,并在可能的情况下使用领域。
这是我要保存它的地方:
class CellVC: UITableViewCell {
var scorepts: Int = 0
let realm = try! Realm()
var infosScore: Results<ScoreInfos>?
@IBAction func minusPressed(_ sender: Any) {
if scorepts != 0 {
scorepts -= 1
countScore.text = "\(scorepts)"
// save the score of the this cell cell
}
}
@IBAction func addPressed(_ sender: Any) {
scorepts += 1
countScore.text = "\(scorepts)"
// save the score of this cell cell
}
然后,当它保存时,我需要在视图加载时加载单元格分数。
感谢您的帮助。
I would like to save a score in a cell that I saved with Realm.
Here is an image of my program.
When I press the top left button, an alert pops up to add a new cell with a label. The cell is saved with realm and is displayed properly. Then on the cell, there is two buttons on each side which can add or subtract a number to the score under the label of the cell.
Now I want to save the score when I change it of each cell and if possible with realm too.
Here is where I want to save it :
class CellVC: UITableViewCell {
var scorepts: Int = 0
let realm = try! Realm()
var infosScore: Results<ScoreInfos>?
@IBAction func minusPressed(_ sender: Any) {
if scorepts != 0 {
scorepts -= 1
countScore.text = "\(scorepts)"
// save the score of the this cell cell
}
}
@IBAction func addPressed(_ sender: Any) {
scorepts += 1
countScore.text = "\(scorepts)"
// save the score of this cell cell
}
Then when it's saved, I need to load the cell scores when the view loads.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论