[英]How to add a new cell by press a Add button and save the text into Coredata
[英]how to save the action of a button press inside of a cell, so that I can add an image without it duplicating or disappearing
我有一个tableViewController
,它具有三个功能,其中两个运行成功。
通过按工具栏内的按钮添加单元格 = 有效
能够将文本插入到单元格内的 UITextView 中,而无需文本复制和移动 = 有效
按下单元格中的按钮时,会出现 checkMarkImage,滚动和移动时不会被复制 = 不起作用
checkMarkImage
不会留在按下按钮的单元格中。 滚动时它会重新出现,有时会消失,尽管我努力使用布尔值来跟踪已被选中的单元格。
我的 customCellClass 内部按钮的配置:
@IBAction func checkMarkButton(_ sender: UIButton) {
if checkedOff{
UIImageView.animate(withDuration: 0.3, delay: 0, options: [], animations: {
self.checkMarkImage.alpha = 0.0
self.notesTextView.isEditable = true
self.notesTextView.textColor = .white
self.checkedOff = false
},completion: nil)
}
else{
UIImageView.animate(withDuration: 0.3, delay: 0, options: [], animations: {
self.checkMarkImage.alpha = 1.0
self.notesTextView.isEditable = false
self.notesTextView.textColor = .orange
self.checkedOff = true
}, completion: nil)
}
}
cellForRowAt
中单元格的处理:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "TableViewNotesCell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! TableViewNotesCell
cell.notesTextView.text = cellNumber[indexPath.row]
if cellNumber[indexPath.row] < " "{
print("celltext is less than nothing")
cell.notesTextView.textColor = .white
cell.notesTextView.isEditable = true
cell.checkMarkImage.alpha = 0.0
}
else{
if cell.checkedOff{
print("cell has been checked off")
cell.notesTextView.textColor = .orange
cell.notesTextView.isEditable = false
cell.checkMarkImage.alpha = 1.0
}
}
我期望cell的checkMarkImage
停留在按钮被按下的cell,但实际效果是checkMarkImage
重新出现,滚动的时候,有时会完全消失
我担心这样做你不会达到预期的结果。 使用UITableView
或UICollectionView
时必须保留数据,因为它们在滚动时重用Cell
。 所以当你滚动 UITableView 时,你会得到重复的图像或有时会丢失它。 你可以做的是:
dataSource
来保存 TableView 的数据。TableView
。CoreData
/ Sqllight
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.